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 => 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) => u a -> (Vector a) ->
> (Vector a) -> (Vector a)
> ...

Another approach is to make Universe a multi-parameter type class:

class (RealFrac a, Floating a) => Universe u a | u -> a where
  distanceVector :: u -> Vector a -> Vector a -> Vector a
...

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

Peace,
        Dylan

Attachment: pgp00000.pgp
Description: PGP signature

Reply via email to