[Haskell-beginners] Question on data/type
iæfai
iaefai at me.com
Mon Nov 16 11:57:45 EST 2009
I will try to help with my limited knowledge and what I believe to be going on.
When you try to compile:
> data TypeCon a = ValConA a | ValConB [ValConA a] | ValConC [ValConB a]
You get this:
Not in scope: type constructor or class `ValConA'
Not in scope: type constructor or class `ValConB'
What you have here is a type constructor TypeCon and a data constructor ValConA, ValConB, ValConC. When you are constructing your different data constructors (such as ValConA) you have to give it type constructors, or substitutes like a. You can do this:
data TypeCon a = ValConA a | ValConB [TypeCon a]
Regards,
iæfai.
On 2009-11-16, at 12:33 AM, Phillip Pirrip wrote:
> 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
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://www.haskell.org/mailman/listinfo/beginners
More information about the Beginners
mailing list