[Haskell-beginners] Questions on data/type
matwong at rogers.com
Mon Nov 16 00:31:00 EST 2009
I have the following data defined.
data TypeCon a = ValConA a | ValConB [a] | ValConC [[a]]
So I can use functions with type like (a->a->a) -> TypeCon a -> TypeCon a -> TypeCon a
for all 3 value types, and I think is easier to define one single typeclass for (+), (*) etc.
If I want to express the following idea (the following won't compiler):
data TypeCon a = ValConA a | ValConB [ValConA a] | ValConC [ValConB a]
Is this even a good idea? If so how could I proceed? The closest thing I can get to compiler is like this:
data TypeCon a = ValConA a | ValConB [TypeCon a]
Which is a nightmare when I try to manipulate anything in this structure. The alternative is use 3 different type constructors,
data TypeConA a = ValConA a
data TypeConB a = ValConB a
data TypeConC a = ValConC a
but then I can't use one signal typeclass for (+) etc.
More information about the Beginners