
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 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. thx, //pip

2009/11/15 Matthew Wong
If I want to express the following idea (the following won't compiler):
data TypeCon a = ValConA a | ValConB [ValConA a] | ValConC [ValConB a]
In this definition, you are confusing constructors with types. You can't have a list of `ValConB a` -- the type is actually `TypeCon a`.
The alternative is use 3 different type constructors,
data TypeConA a = ValConA a data TypeConB a = ValConB a data TypeConC a = ValConC a
This is more promising. I'd need to see the typeclass you're trying to define to say more. -- Jason Dusek
participants (2)
-
Jason Dusek
-
Matthew Wong