[Haskell-beginners] Multiple declarations of value constructor
Peter Hall
peter.hall at memorphic.com
Wed Dec 19 18:43:38 CET 2012
Something like this?
class TwoValues a where
val1 :: a
val2 :: a
data MyTypeA = ValueA1 | ValueA2
data MyTypeB = ValueB1 | ValueB2
instance TwoValues MyTypeA where
val1 = ValueA1
val2 = ValueA2
instance TwoValues MyTypeB where
val1 = ValueB1
val2 = ValueB2
---
val1 :: MyTypeA -- ValueA1
val2 :: MyTypeB -- ValueB2
Peter
On 19 December 2012 15:52, Emanuel Koczwara <poczta at emanuelkoczwara.pl>wrote:
> Hi,
>
> -- tests.hs
> data MyType1 = Value1 | Value2
> data MyType2 = Value1 | Value2
>
>
> Prelude> :l tests
> [1 of 1] Compiling Main ( tests.hs, interpreted )
>
> tests.hs:3:16:
> Multiple declarations of `Main.Value1'
> Declared at: tests.hs:1:16
> tests.hs:3:16
>
> tests.hs:3:25:
> Multiple declarations of `Main.Value2'
> Declared at: tests.hs:1:25
> tests.hs:3:25
> Failed, modules loaded: none.
>
> If so, how are numbers defined? I can use 1 :: Int or 1 :: Integer. Why
> not Value1 :: MyType1 and Value1 :: MyType2?
>
> Emanuel
>
>
>
>
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://www.haskell.org/mailman/listinfo/beginners
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/beginners/attachments/20121219/44144f21/attachment.htm>
More information about the Beginners
mailing list