defining (-> Bool) as a set

Jorge Adriano jadrian@mat.uc.pt
Tue, 23 Apr 2002 01:00:51 +0100


> class Collection e ce | ce -> e where
>     empty :: ce
>     insert :: e -> ce -> ce
>     member :: e -> ce -> Bool
>
> instance Eq a =3D> Collection a (a -> Bool) where
>     empty =3D (\x -> False)
>     insert e f =3D (\x -> if x =3D=3D e then True else f x)
>     member e f =3D f e

This is way better than my solution...=20

I had never used multi-parameter classes before, so I forgot the function=
al=20
dependency (right name? the "|ce->e"), and there was obviously no need fo=
r my=20
extra constructor.

J.A.