Type design question
Dylan Thurston
dpt@math.harvard.edu
Fri, 25 Jul 2003 15:48:15 -0400
--4Ckj6UjgE2iN1+kY
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
On Fri, Jul 25, 2003 at 08:31:26AM -0700, Hal Daume wrote:
> However, once we fix this, we can see the real problem. Your Universe
> class has a method, distanceVector, of type:
>=20
> | distanceVector :: Universe u, Floating a =3D> u -> Vector a -> Vector a
> -> Vector a
>=20
> And here's the problem. When 'u' is 'OrthorhombicUniverse x', it
> doesn't know that this 'x' is supposed to be the same as the 'a'. One
> way to fix this is to parameterize the Universe data type on the
> element, something like:
>=20
> class Universe u where
> distanceVector :: (RealFrac a, Floating a) =3D> u a -> (Vector a) ->
> (Vector a) -> (Vector a)
> ...
Another approach is to make Universe a multi-parameter type class:
class (RealFrac a, Floating a) =3D> Universe u a | u -> a where
distanceVector :: u -> Vector a -> Vector a -> Vector a
=2E..
You need to use ghc with '-fglasgow-exts' for this.
Peace,
Dylan
--4Ckj6UjgE2iN1+kY
Content-Type: application/pgp-signature
Content-Disposition: inline
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.2 (GNU/Linux)
iD8DBQE/IYl/Veybfhaa3tcRAojQAKCftGt5jChP00NU/9mUs5E8j4fGRACfQqwr
iK/IqB8p0rfO3cgvKC3bzZI=
=9PqW
-----END PGP SIGNATURE-----
--4Ckj6UjgE2iN1+kY--