Skip to content
GitLab
Projects Groups Topics Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
  • Register
  • Sign in
  • GHC GHC
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributor statistics
    • Graph
    • Compare revisions
    • Locked files
  • Issues 5.5k
    • Issues 5.5k
    • List
    • Boards
    • Service Desk
    • Milestones
    • Iterations
  • Merge requests 639
    • Merge requests 639
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Artifacts
    • Schedules
    • Test cases
  • Deployments
    • Deployments
    • Releases
  • Packages and registries
    • Packages and registries
    • Model experiments
  • Analytics
    • Analytics
    • CI/CD
    • Code review
    • Insights
    • Issue
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • Glasgow Haskell CompilerGlasgow Haskell Compiler
  • GHCGHC
  • Issues
  • #3005

Normalize fully-applied type functions prior to display

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

When a type function is fully-applied, as Product is in this case, it would be nice if GHC could simplify it prior to display.

This would result in the following output for this example:

:t a `times` a
a `times` a :: Matrix Two Two Integer

I have attached the files necessary to run this test case, although a simpler one could be constructed.

Edited Mar 09, 2019 by Ian Lynagh <igloo@earth.li>
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information
Assignee
Assign to
Time tracking