Display of associated types in GHCi
Douglas McClean
douglas.mcclean at gmail.com
Fri Feb 6 12:20:43 EST 2009
Thanks Brian and Simon.
In case anyone is interested, this is now ticket 3005.
-Doug McClean
On Fri, Feb 6, 2009 at 10:55 AM, Simon Peyton-Jones
<simonpj at microsoft.com>wrote:
> 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
>
>
>
> *From:* glasgow-haskell-users-bounces at haskell.org [mailto:
> glasgow-haskell-users-bounces at haskell.org] *On Behalf Of *Douglas McClean
> *Sent:* Friday, February 06, 2009 5:32 AM
> *To:* glasgow-haskell-users at haskell.org
> *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
>
--
J. Douglas McClean
(781) 561-5540 (cell)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/glasgow-haskell-users/attachments/20090206/eb5bac95/attachment-0001.htm
More information about the Glasgow-haskell-users
mailing list