[GHC] #12882: Unexpected constraint when using ExistentialQuantification

GHC ghc-devs at haskell.org
Sun Nov 27 14:56:17 UTC 2016


#12882: Unexpected constraint when using ExistentialQuantification
-------------------------------------+-------------------------------------
        Reporter:  danilo2           |                Owner:
            Type:  bug               |               Status:  closed
        Priority:  normal            |            Milestone:
       Component:  Compiler (Type    |              Version:  8.0.1
  checker)                           |
      Resolution:  invalid           |             Keywords:
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 mpickering):

 OK - I got it to compile now, I was missing scoped type variables. Here is
 the more usual way to write your data type.

 {{{
 {-# LANGUAGE ExistentialQuantification #-}
 {-# LANGUAGE ScopedTypeVariables #-}
 {-# LANGUAGE GADTs #-}

 import Data.Typeable

 data Elem t where
   Elem :: Typeable t => Int -> Elem t

 tst1 :: forall a. Elem a -> TypeRep
 tst1 (Elem _) = typeRep (Proxy :: Proxy a)
 }}}

 Then it is clear why you must pattern match on `Elem` in order to discover
 that you have the `Typeable` constraint. You could have another
 constructor which doesn't bind it. For example,

 {{{
 data Elem t where
   Elem :: Typeable t => Int -> Elem t
   Elem2 :: t -> Elem t
 }}}

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


More information about the ghc-tickets mailing list