# Display of associated types in GHCi

Simon Peyton-Jones simonpj at microsoft.com
Fri Feb 6 10:55:35 EST 2009

```Douglas.

Good suggestion.  I believe it's already been proposed that typese are normalised (wrt type functions) before being displayed, but I can't find the ticket.  Do create a feature request on Trac, with your example.  Thanks!

Simon

Sent: Friday, February 06, 2009 5:32 AM
Subject: Display of associated types in GHCi

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)?

Thanks,
Doug McClean
-------------- next part --------------
An HTML attachment was scrubbed...