Misleading error message with forgotten "do"
In the following (simplified) code, I forgot to add the do keyword, when doing some refactoring. This caused GHC to give a strange error message that said approximately "The function F is applied to two arguments, but its type T has only two"... which is odd!
import Control.Monad.RWS ( evalRWS, RWS ) import Control.Monad.Writer.Class ( tell ) main = print $ evalRWS (go 1) () () go :: Int -> RWS () [String] () () go i = --Oops, forgot a do here return (show i) >>= (\l -> tell [l]) -- go $ i + 1 go i
Strangely, replacing the "go i" line with the commented-out line above it gives a sensible error message, the "Possible cause: `\l -> tell [l]' is applied to too many arguments" message, which is correct, and would've pointed me straight to the problem.
The invalid error message, which appears to be the same using GHC 7.6.3 and 7.8.3, is:
NFA.hs:8:25: Couldn't match type ‘String -> Control.Monad.Trans.RWS.Lazy.RWST () [String] () Data.Functor.Identity.Identity ()’ with ‘()’ Expected type: Int -> String -> Control.Monad.Trans.RWS.Lazy.RWST () [String] () Data.Functor.Identity.Identity () Actual type: Int -> () The function ‘\ l -> tell [l]’ is applied to two arguments, but its type ‘(Int -> RWS () [String] () ()) -> Int -> ()’ has only two In the second argument of ‘(>>=)’, namely ‘(\ l -> tell [l]) go i’ In the expression: return (show i) >>= (\ l -> tell [l]) go i