haskell sum type multiple declaration error

前端 未结 4 1296
情歌与酒
情歌与酒 2020-12-22 03:55
data A=A
data B=B
data AB=A|B

Which makes a sum type AB from A and B.

but the last line induces a compile error \"multiple declarations of

4条回答
  •  时光说笑
    2020-12-22 04:38

    Because the type of the value created using data constructor A or B will be ambiguous. When I have a = B for instance, what is the type of a? It is A or AB?

    You should consider using different data constructor as follows:

    data A = MkA
    data B = MkB
    data AB = A A | B B
    

提交回复
热议问题