Ticket #3613 (closed bug: fixed)
Better error messages for do-notation
| Reported by: | simonpj | Owned by: | |
|---|---|---|---|
| Priority: | normal | Milestone: | 7.0.1 |
| Component: | Compiler (Type checker) | Version: | 6.10.4 |
| Keywords: | Cc: | red5_2@…, michal.terepeta@… | |
| Operating System: | Unknown/Multiple | Architecture: | Unknown/Multiple |
| Type of failure: | Incorrect warning at compile-time | Difficulty: | Unknown |
| Test Case: | typecheck/should_fail/T3613 | Blocked By: | |
| Blocking: | Related Tickets: |
Description
C Rodrigues [red5_2@…] writes: In this example, fun1 and fun2 are basically the same. The type error is because they try to run an IO () together with a Maybe ().
> import Control.Monad
>
> foo :: Maybe ()
> foo = return ()
>
> bar :: IO ()
> bar = return ()
>
> fun1 = let fooThen m = foo>> m
> in fooThen (bar>> undefined)
>
> fun2 = let fooThen m = foo>> m
> in fooThen (do {bar; undefined})
With ghc 6.10.4, both functions attribute the error message to `bar'. However, the expected and inferred monads are swapped.
- fun1 produces the error message:
Couldn't match expected type `Maybe a' against inferred type `IO ()' In the first argument of `(>>=)', namely `bar'
- fun2 produces the error message:
Couldn't match expected type `IO ()' against inferred type `Maybe ()' In a stmt of a 'do' expression: bar
It's confusing because 'bar' is inferred to have type Maybe (), even though it's explicitly declared to be an IO ().
Change History
Note: See
TracTickets for help on using
tickets.
