[Haskell-beginners] Question on data/type
Phillip Pirrip
ppirrip at gmail.com
Mon Nov 16 00:33:51 EST 2009
Hi,
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 I guess is to use 3 different type constructors,
data TypeConA a = ValConA a
data TypeConB a = ValConB [ValConA a]
data TypeConC a = ValConC [ValConB a]
but then I can't use one signal typeclass for (+) etc. Am I correct?
thx,
//pip
More information about the Beginners
mailing list