[GHC] #10405: Pattern synonym fails with (Exp Bool) but works with (t ~ Bool => Exp Bool)

GHC ghc-devs at haskell.org
Mon May 11 19:21:44 UTC 2015


#10405: Pattern synonym fails with (Exp Bool) but works with (t ~ Bool => Exp Bool)
-------------------------------------+-------------------------------------
              Reporter:              |             Owner:
  Iceland_jack                       |            Status:  new
                  Type:  bug         |         Milestone:
              Priority:  normal      |           Version:  7.10.1-rc1
             Component:  Compiler    |  Operating System:  Linux
  (Type checker)                     |   Type of failure:  GHC rejects
              Keywords:              |  valid program
          Architecture:  x86         |        Blocked By:
             Test Case:              |   Related Tickets:
              Blocking:              |
Differential Revisions:              |
-------------------------------------+-------------------------------------
 The following compiles just fine:

 {{{#!hs
 data Exp a where
   B :: Bool -> Exp Bool

 pattern Tru = B True

 pr :: Exp a -> String
 pr Tru = "true"
 }}}

 but add a signature to `Tru`…

 {{{#!hs
 pattern Tru :: Exp Bool
 pattern Tru = B True
 }}}

 …and it fails to compile

 {{{#!hs
 % ghci -ignore-dot-ghci /tmp/Bug.hs
 GHCi, version 7.10.0.20150316: http://www.haskell.org/ghc/  :? for help
 [1 of 1] Compiling Main             ( /tmp/Bug.hs, interpreted )

 /tmp/Bug.hs:11:4:
     Couldn't match type ‘a’ with ‘Bool’
       ‘a’ is a rigid type variable bound by
           the type signature for pr :: Exp a -> String at /tmp/Bug.hs:10:7
     Expected type: Exp a
       Actual type: Exp Bool
     Relevant bindings include
       pr :: Exp a -> String (bound at /tmp/Bug.hs:11:1)
     In the pattern: Tru
     In an equation for ‘pr’: pr Tru = "true"
 Failed, modules loaded: none.
 }}}

 Checking the inferred type of `pattern Tru = B True` I get

 {{{#!hs
 ghci> :i Tru
 pattern Tru :: t ~ Bool => Exp t
 }}}

 which works as expected

 {{{#!hs
 pattern Tru :: t ~ Bool => Exp t
 pattern Tru = B True

 pr :: Exp a -> String
 pr Tru = "true"
 }}}

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


More information about the ghc-tickets mailing list