RE: [Haskell] A question about a possible bug in GHC regarding GADTs and type classes

[redirecting to ghc-users] This code works with the HEAD, where I recently fixed the interaction between GADTs and type classes. You'll need to use a HEAD compiler (not 6.6) though. Someone else may help you with the TyRange stuff; I'm just referring to the Num constraint in your data type. Simon | -----Original Message----- | From: haskell-bounces@haskell.org [mailto:haskell-bounces@haskell.org] On Behalf Of Pablo Nogueira | Sent: 17 January 2007 15:36 | To: haskell@haskell.org | Subject: [Haskell] A question about a possible bug in GHC regarding GADTs and type classes | | Hi, | | I've been told the following short code is correct but it's GHC's | fault it does not type check. | Is that the case? | | -- | {-# OPTIONS -fglasgow-exts #-} | | -- An expression GADT: | | data Exp :: * -> * where | LitNum :: Num a => a -> Exp a | LitBool :: Bool -> Exp Bool | Plus :: Num a => Exp a -> Exp a -> Exp a | And :: Exp Bool -> Exp Bool -> Exp Bool | If :: Exp Bool -> Exp a -> Exp a -> Exp a | | -- An expression evaluator: | | evalExp :: Exp a -> a | evalExp (LitNum i) = i | evalExp (LitBool b) = b | evalExp (Plus x y) = evalExp x + evalExp y | evalExp (And x y) = evalExp x && evalExp y | evalExp (If c t e) = if (evalExp c) then (evalExp t) else (evalExp e) | -- | | The type checker complains that evalExp needs a Num constraint on its | type signature. | This can't be right, for Bool is not an instance of Num, right? | | Is it the case that the interaction between GADTs and type classes is | not fully worked out yet?
participants (1)
-
Simon Peyton-Jones