Display of associated types in GHCi
douglas.mcclean at gmail.com
Fri Feb 6 00:31:45 EST 2009
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)?
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Glasgow-haskell-users