Skip to content

Compiler error implies incorrect implicit import of a ((->)a) Monad instance

Take the following (incorrect) source:

fun :: Integer -> String
fun x = "123"

main = do
  s <- readFile "file.in"
  let m = read s
  writeFile "file.out" (return fun m)

Compile it:

jkff@jkff-laptop:~$ ghci tmp.hs
GHCi, version 6.10.2: http://www.haskell.org/ghc/  :? for help
Loading package ghc-prim ... linking ... done.
Loading package integer ... linking ... done.
Loading package base ... linking ... done.
[1 of 1] Compiling Main             ( tmp.hs, interpreted )

tmp.hs:8:31:
    Couldn't match expected type `String'
           against inferred type `Integer -> String'
    In the first argument of `return', namely `fun'
    In the second argument of `writeFile', namely `(return fun m)'
    In the expression: writeFile "file.out" (return fun m)
Failed, modules loaded: none.

The error looks like if the compiler has implicitly imported Control.Monad.Instances including the instance for ((->)a). It shouldn't have done so, because Prelude doesn't include this instance. NoImplicitPrelude doesn't help.

Trac metadata
Trac field Value
Version 6.10.2
Type Bug
TypeOfFailure OtherFailure
Priority normal
Resolution Unresolved
Component Compiler
Test case
Differential revisions
BlockedBy
Related
Blocking
CC
Operating system
Architecture
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information