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

This feature is mentioned as a todo on the GHC wiki: http://hackage.haskell.org/trac/ghc/wiki/TypeFunctionsStatus (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). http://hackage.haskell.org/trac/ghc/wiki/ReportABug Thanks, 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)? Thanks, Doug McClean _________________________________________________________________ More than messages–check out the rest of the Windows Live™. http://www.microsoft.com/windows/windowslive/

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@haskell.org [mailto:glasgow-haskell-users-bounces@haskell.org] On Behalf Of Douglas McClean Sent: Friday, February 06, 2009 5:32 AM To: glasgow-haskell-users@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

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
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@haskell.org [mailto: glasgow-haskell-users-bounces@haskell.org] *On Behalf Of *Douglas McClean *Sent:* Friday, February 06, 2009 5:32 AM *To:* glasgow-haskell-users@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)
participants (3)
-
Brian Bloniarz
-
Douglas McClean
-
Simon Peyton-Jones