More type design questions
Konrad Hinsen
hinsen@cnrs-orleans.fr
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:
=2E..
Thanks for the explanation! It seems that what I need (but what apparentl=
y=20
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
=2E..
> 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=
e.
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=
ists=20
of vectors and then be able to apply the functions in class "Vect" to the=
m.=20
If I introduce a new type, then I will have to put wrapper functions in m=
any=20
places. I really want a type that is a list *and* an instance of class Ve=
ct.
In fact, what I'd really like to have is even more general:
instance Vect v a =3D> Vect [Vect v a] where
=2E..
i.e. defining that a list of any Vect instance is itself a Vect instance.=
But=20
I could live with the case that I presented initially.
Konrad.