[GHC] #14004: G

GHC ghc-devs at haskell.org
Sat Jul 22 14:01:38 UTC 2017


#14004: G
-------------------------------------+-------------------------------------
        Reporter:  zaoqi             |                Owner:  (none)
            Type:  feature request   |               Status:  new
        Priority:  normal            |            Milestone:
       Component:  Compiler          |              Version:  7.10.3
      Resolution:                    |             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 bgamari):

 Moreover, there is no way to satisfy the `Eq a` constraint needed by `geq
 a b`. Afterall, the `a` type variable here is brought into scope by
 pattern-matching on the `Dyn` constructor which provides no constraints;
 not even `Typeable`, so it's not even possible to know at runtime whether
 the bound `a` and `b` values are of the same type.

 To be able to make this comparison work you would need something like,
 {{{#!hs
 data Dyn :: * where
     Dyn :: (Eq a, Typeable a) => a -> Dyn

 instance Eq Dyn where
     Dyn (a :: a) == Dyn (b :: b)
       | Just HRefl <- ra `eqTypeRep` rb = a == b
       | otherwise                       = False
       where ra = typeRep :: TypeRep a
             rb = typeRep :: TypeRep b
 }}}
 For instance,
 {{{
 λ> Dyn (1 :: Int) == Dyn (2 :: Int)
 False
 λ> Dyn (1 :: Int) == Dyn (1 :: Int)
 True
 }}}

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


More information about the ghc-tickets mailing list