
#9612: Use functional dependencies to give more specific error messages -------------------------------------+------------------------------------- Reporter: rwbarton | Owner: Type: feature request | Status: new Priority: normal | Milestone: Component: Compiler (Type | Version: 7.8.3 checker) | Operating System: Keywords: | Unknown/Multiple Architecture: Unknown/Multiple | Type of failure: Difficulty: Unknown | None/Unknown Blocked By: | Test Case: Related Tickets: | Blocking: | Differential Revisions: -------------------------------------+------------------------------------- An example from http://www.reddit.com/r/haskell/comments/2gryy8/stdlib_monad_error_messages_...: {{{#!hs f ::(Eq a) => a -> (Int, a) -> Writer [(Int, a)] (Int, a) f y (n,x) | y == x = return (n+1, x) | otherwise = do tell (n,x) return (1,y) }}} {{{ Could not deduce (MonadWriter (Int, a) (WriterT [(Int, a)] Data.Functor.Identity.Identity)) arising from a use of ‘tell’ from the context (Eq a) bound by the type signature for f :: Eq a => a -> (Int, a) -> Writer [(Int, a)] (Int, a) at 180.hs:42:5-57 In a stmt of a 'do' block: tell (n, x) In the expression: do { tell (n, x); return (1, y) } In an equation for ‘f’: f y (n, x) | y == x = return (n + 1, x) | otherwise = do { tell (n, x); return (1, y) } }}} GHC could realize that the class `MonadWriter m w` has a functional dependency `w -> m` and notice that there is an instance `MonadWriter w (WriterT w m1)` whose `m`-part unifies with that of the needed constraint. Therefore the error cannot be a missing instance, and GHC could give a more friendly error message like {{{ Couldn't match expected type `[(Int, a)]' with actual type `(Int, a)' when unifying the instance `MonadWriter w (WriterT w m1)' with the constraint `MonadWriter (Int, a) (WriterT [(Int, a)] Identity)' arising from a use of 'tell' In a stmt of a 'do' block: tell (n, x) In the expression: ... }}} (Or, if necessary, `Could not deduce [(Int, a)] ~ (Int, a) from the context (Eq a) ...`) -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9612 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler