[GHC] #9637: Type level programming needs an error function

GHC ghc-devs at haskell.org
Mon Sep 29 18:06:23 UTC 2014


#9637: Type level programming needs an error function
-------------------------------------+-------------------------------------
              Reporter:  augustss    |            Owner:
                  Type:  feature     |           Status:  new
  request                            |        Milestone:
              Priority:  normal      |          Version:  7.8.3
             Component:  Compiler    |         Keywords:
            Resolution:              |     Architecture:  Unknown/Multiple
      Operating System:              |       Difficulty:  Unknown
  Unknown/Multiple                   |       Blocked By:
       Type of failure:              |  Related Tickets:
  None/Unknown                       |
             Test Case:              |
              Blocking:              |
Differential Revisions:              |
-------------------------------------+-------------------------------------

Comment (by augustss):

 Here's what I'm using now, and it works nicely.  But better names would be
 nice.

 {{{#!hs
 type family Error (a :: k1) :: k2 where { }
 data ErrorAnd (a :: k1) (b :: k2)
 }}}

 When the type checker encounters the Error function it generates the error
 message according to the following pseudo code:

 {{{#!hs
 flatten (Symbol s) = s
 flatten (ErrorAnd t1 t2) = flatten t1 ++ flatten t2
 flatten t = prettyPrint t
 }}}

 So for instance `Error "Oh noes!"` will generate the error message "Oh
 noes!".  And {{{Error ("Mismatch between " `ErrorAnd` t1 `ErrorAnd` " and
 " `ErrorAnd` t2)}}} will generate "Mismatch between ... and ...", where
 ... are the pretty printing of the types t1 and t2 respectively.

--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/9637#comment:3>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler


More information about the ghc-tickets mailing list