data Prop = Const Bool
| Var Char
| Not Prop
| And Prop Prop
| Imply Prop Prop
I am implementing the above data contructor with a minor addition,
data Prop = Const Bool
| Var Char
| Not Prop
| Or Prop Prop
| And Prop Prop
| Imply Prop Prop
When I try to make another data contructor below that uses the previously defined constructor,
data Formula = Const Bool
| Var Prop
| Not Formula
| And Formula Formula
| Or Formula Formula
| Imply Formula Formula
I get this error: "Multiple declarations of 'Const'"
The same error follows with Not
, And
, Imply
, and Or
. Why does Haskell not allow this?
Haskell doesn't allow this because it would be ambiguous. The value constructor Prop
is effectively a function, which may be clearer if you ask GHCi about its type:
> :t Const
Const :: Bool -> Prop
If you attempt to add one more Const
constructor in the same module, you'd have two 'functions' called Const
in the same module. You can't have that.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With