Multiparameter class confusion

Dylan Thurston dpt@math.harvard.edu
Sat, 7 Jun 2003 02:18:35 +0200


--ikeVEW9yuYc//A+q
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

On Wed, Jun 04, 2003 at 01:21:00PM +0100, Graham Klyne wrote:
> There is a recurring difficulty I'm having using multiparameter classes.
>=20
> Most recently, I have a class Rule:
> [[
> class (Expression ex, Eq (rl ex)) =3D> Rule rl ex where
>   ...
> ]]
>=20
> Which I wish to instantiate for a type GraphClosure via something like:
> [[
> instance (Label lb, LDGraph lg lb) =3D> Expression (lg lb) where
>   ...
>=20
> data (Label lb, LDGraph lg lb) =3D> GraphClosure lg lb =3D ...
>=20
> instance Rule GraphClosure (NSGraph RDFLabel) where
>   ...
>=20
> ]]
> ...
> I think that what I really *want* to do here is change the kind of=20
> GraphClosure to be (* -> *) rather than (* -> * -> *).  But if I try this:
>=20
> [[
> data (Label lb, LDGraph lg lb) =3D> GraphClosure (lg lb) =3D ...
> ]]
> a syntax error is reported by Hugs and GHC.

You haven't quite shown enough of your code.  One thing you might
consider is dropping the context from the definition of the
GraphClosure type.  Class contexts in data declarations end up being
largely useless, anyway, since the dictionary is never actually used
for anything.  (There was a thread a few years ago about this.)
You could then write

> data GraphClosure lglb =3D ...

But this only works if the definition of GraphClosure only uses (lg
lb), not the individual pieces.

Peace,
	Dylan


--ikeVEW9yuYc//A+q
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.2 (GNU/Linux)

iD8DBQE+4S9bVeybfhaa3tcRAkz6AJ92lPE9Oix/CNGaId+YOGCqid+6PACbBbTL
7vcaqrGIet2XHV9MhVf/Mnw=
=bwZD
-----END PGP SIGNATURE-----

--ikeVEW9yuYc//A+q--