Ticket #1158 (new bug)
Problem with GADTs and explicit type signatures
| Reported by: | guest | Owned by: | simonpj |
|---|---|---|---|
| Priority: | lowest | Milestone: | _|_ |
| Component: | Compiler | Version: | 6.6 |
| Keywords: | Cc: | ||
| Operating System: | Unknown/Multiple | Architecture: | Unknown/Multiple |
| Type of failure: | Difficulty: | Unknown | |
| Test Case: | Blocked By: | ||
| Blocking: | Related Tickets: |
Description
{-# OPTIONS_GHC -fglasgow-exts #-}
module Main where
data Exp a where
Val :: a -> Exp b
App :: Exp a -> Exp b
instance Show (Exp a) where
show (Val _) = "Val"
show (App _) = "App"
class LiftToExp a b where
liftToExp :: a -> Exp b
instance LiftToExp (Exp a) a where
liftToExp = id
instance Floating a => LiftToExp a b where
liftToExp v = Val v :: Exp b
{-
Uncommenting the type signature below causes GHCi to fail to load the file:
test.hs:45:14:
Overlapping instances for LiftToExp a a11
arising from use of `liftToExp' at test.hs:45:14-24
Matching instances:
instance (Floating a) => LiftToExp a b -- Defined at test.hs:19:0
instance LiftToExp (Exp a) a -- Defined at test.hs:16:0
(The choice depends on the instantiation of `a, a11'
Use -fallow-incoherent-instances to use the first choice above)
In the first argument of `App', namely `(liftToExp x)'
In the expression: App (liftToExp x)
In the definition of `test': test x = App (liftToExp x)
However typing :t test at the GHCi prompt gives this exact signature.
Tested with GHC 6.6 (compiler and interpreter) under OS X 10.4.8 on an iMac G5.
-}
--test :: (LiftToExp a a1) => a -> Exp b
test x = App (liftToExp x)
main = putStrLn $ show (test (3.0::Float)::Exp Int)
Change History
Note: See
TracTickets for help on using
tickets.
