[GHC] #12975: Suggested type signature for a pattern synonym causes program to fail to type check

GHC ghc-devs at haskell.org
Thu Dec 15 12:56:05 UTC 2016


#12975: Suggested type signature for a pattern synonym causes program to fail to
type check
-------------------------------------+-------------------------------------
        Reporter:  ocharles          |                Owner:
            Type:  bug               |               Status:  new
        Priority:  normal            |            Milestone:
       Component:  Compiler (Type    |              Version:  8.0.1
  checker)                           |             Keywords:
      Resolution:                    |  PatternSynonyms
Operating System:  Unknown/Multiple  |         Architecture:
                                     |  Unknown/Multiple
 Type of failure:  None/Unknown      |            Test Case:
      Blocked By:                    |             Blocking:
 Related Tickets:                    |  Differential Rev(s):
       Wiki Page:                    |
-------------------------------------+-------------------------------------

Comment (by simonpj):

 The reported type is sort of right:
 {{{
 Cast :: forall b. Typeable b => forall a. Typeable a => b -> T
 }}}
 That is, you can match a value of any type `b` provided it is typeable. So
 {{{
 f (Cast x) = rhs
 }}}
 means pretty much
 {{{
 f (MkT y) = case cast y of
               Just x -> rhs
 }}}
 Inside `rhs` we have access to the `Typeable a` constraint bound by `MkT`;
 that's what the `Typeable a` constraint in the inferred type is saying.

 But this `Typeable a` provided constraint is no use to `rhs` because we
 have no values of type `a`. So Matthew's type is less confusing
 {{{
 pattern Cast :: Typeable b => b -> T
 }}}
 Offering useless constraints is bad enough; but worse, as you report, it's
 rejected as ambiguous (for the same reason) if you specify it in a user
 signature.  That is indeed confusing.

 What I can't see is a robust and convenient way to eliminate the
 unnecessary constraints and existential variables.

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


More information about the ghc-tickets mailing list