More type design questions

Konrad Hinsen
Mon, 18 Aug 2003 18:07:52 +0200

On Monday 18 August 2003 09:25, Bernard James POPE wrote:

> The kinds are there to help the compiler check whether types are well
> formed (including such things as instance declarations).
> The syntax for kinds is very simple:

Thanks for the explanation! It seems that what I need (but what apparentl=
doesn't exist) is the equivalent of a lambda expression for type=20
constructors, then I could write something like

instance Vect (\a -> [Vector a]) a where

> One way around this might be to define a new type:
>    newtype ListVector a =3D LV [Vector a]
>    instance Vect ListVector a where
>      (<+>) (LV l1) (LV l2) =3D LV $ zipWith (<+>) l1 l2
> Though is is bit ugly to have to mention the LV constructor all the tim=

It's not just ugly, it destroys the generality of my code. I would like t=
o be=20
able to have generic list processing functions (think of "map") produce l=
of vectors and then be able to apply the functions in class "Vect" to the=
If I introduce a new type, then I will have to put wrapper functions in m=
places. I really want a type that is a list *and* an instance of class Ve=

In fact, what I'd really like to have is even more general:

instance Vect v a =3D> Vect [Vect v a] where

i.e. defining that a list of any Vect instance is itself a Vect instance.=
I could live with the case that I presented initially.