Opened 8 years ago

Closed 8 years ago

#2885 closed bug (duplicate)

Late and confusing error on uncallable class method

Reported by: blamario Owned by:
Priority: normal Milestone:
Component: Compiler Version: 6.10.1
Keywords: Cc:
Operating System: Linux Architecture: x86_64 (amd64)
Type of failure: None/Unknown Test Case:
Blocked By: Blocking:
Related Tickets: Differential Rev(s):
Wiki Page:


This has been discussed on Haskell Café (, I'm reporting it here in case something can be done to help other confused souls in future.

In short, the error message reported by GHC (6.10.1):

    Could not deduce (Container x y) from the context (Container x y1)
      arising from a use of `wrapper' at Test.hs:11:22-30
    Possible fix:
      add (Container x y) to the context of
        the type signature for `liftWrap'
    In the expression: wrapper x
    In the expression:
        (if wrapper x then rewrap . f . unwrap else id) x
    In the definition of `liftWrap':
        liftWrap f x = (if wrapper x then rewrap . f . unwrap else id) x

does not begin to indicate that the actual problem with the following program is in the type class declaration:

   {-# LANGUAGE MultiParamTypeClasses, FlexibleInstances #-}

   import Data.Maybe

   class Container x y where
      wrapper :: x -> Bool
      unwrap :: x -> y
      rewrap :: y -> x

   liftWrap :: Container x y => (y -> y) -> (x -> x)
   liftWrap f x = (if wrapper x then rewrap . f . unwrap else id) x

   instance Container (Maybe x) x where
      wrapper = isJust
      unwrap = fromJust
      rewrap = Just

   main = print (liftWrap (succ :: Int -> Int) (Just 1 :: Maybe Int))

If the 'wrapper' method can never be called in any possible context, there should be an error report at the point where the method is declared. I don't think that's a controversial statement. Even if the compiler allows the declaration under the assumption that the useless method is never called, it should at least emit a strong warning.

Change History (1)

comment:1 Changed 8 years ago by simonpj

difficulty: Unknown
Resolution: duplicate
Status: newclosed

Yes, you are quite right. This is a bad and long-standing problem; the ticket that gathers the pointers is #1897. I've cross-referenced it from here, and will close this as a duplicate.


Note: See TracTickets for help on using tickets.