Type design question

Dylan Thurston dpt@math.harvard.edu
Fri, 25 Jul 2003 15:48:15 -0400

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:
> | distanceVector :: Universe u, Floating a =3D> u -> Vector a -> Vector a
> -> Vector a
> 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:
> 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

You need to use ghc with '-fglasgow-exts' for this.


Content-Type: application/pgp-signature
Content-Disposition: inline

Version: GnuPG v1.2.2 (GNU/Linux)