Display of associated types in GHCi

Brian Bloniarz phunge0 at hotmail.com
Fri Feb 6 09:32:03 EST 2009

This feature is mentioned as a todo on the GHC wiki:
(under "additional features"). I think it's just something that'd
be nice but hasn't made it to the top of the implementers'
priorities yet.

The next step is probably to submit a feature request and add
yourself on the CC: list (to "vote" for this feature).

Brian Bloniarz

I have a question about the display of names for associated types in GHCi.

I have a module with a matrix type constructor:
> data (Natural r, Natural c) => Matrix r c t = Matrix [[t]] deriving (Eq)

which uses type-level naturals to provide dimension checking.

A type class for multiplication:

> class Multiply a b where
>  type Product a b
>  times :: a -> b -> Product a b

and an instance for matrix multiplication:

> instance (Natural a, Natural b, Natural c, Num t) => Multiply (Matrix a b t) (Matrix b c t) where
>  type Product (Matrix a b t) (Matrix b c t) = Matrix a c t

>  times m1 m2 = ...

All of this works really well, I get dimension checking (and inference), and lot of other goodies.

My question has to do with the following GHCi session:

*Main> let a = matrix two two [[1,1],[2,6]]

*Main> :t a
a :: Matrix Two Two Integer
*Main> :t a `times` a
a `times` a :: Product
                 (Matrix Two Two Integer) (Matrix Two Two Integer)

Am I correct that the type denoted by "Product (Matrix Two Two Integer) (Matrix Two Two Integer)" is always "Matrix Two Two Integer"? It certainly behaves that way in more complicated expressions, which is desirable.

If so, could someone explain the reason why GHCi chooses not to simplify such types for display? Could it? Is there a reason why such simplification would be undesirable (when it is possible, I understand that it wouldn't be if type variables were present)?

Doug McClean

More than messages–check out the rest of the Windows Live™.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/glasgow-haskell-users/attachments/20090206/4e11258e/attachment.htm

More information about the Glasgow-haskell-users mailing list