Ticket #1158 (new bug)

Opened 5 years ago

Last modified 3 years ago

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

Changed 5 years ago by simonpj

  • owner set to simonpj
  • priority changed from normal to lowest
  • milestone set to _|_

This one has come up quite recently. It's not really a bug... or at least arguably not so. Since it's come up again I've written some notes in GHC's user documentation about it.

 http://haskell.org/haskellwiki/GHC/Type_system#Type_signatures_and_ambiguity

Here's a Haskell-Cafe thread in which the same issue arose:  http://www.haskell.org/pipermail/haskell-cafe/2007-January/021521.html

I'm going to leave this open at low priority, so we don't forget about it.

Changed 3 years ago by simonmar

  • architecture changed from Unknown to Unknown/Multiple

Changed 3 years ago by simonmar

  • os changed from Unknown to Unknown/Multiple
Note: See TracTickets for help on using tickets.