Opened 6 years ago

Closed 6 years ago

#3185 closed bug (invalid)

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

Reported by: jkff Owned by:
Priority: normal Milestone:
Component: Compiler Version: 6.10.2
Keywords: Cc:
Operating System: Linux Architecture: x86
Type of failure: Test Case:
Blocked By: Blocking:
Related Tickets: Differential Revisions:

Description

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.

Change History (1)

comment:1 Changed 6 years ago by jkff

  • Resolution set to invalid
  • Status changed from new to closed

Oops, people explained to me the real reason of this behavior, which turned out to be quite logical. Closing as invalid.

Note: See TracTickets for help on using tickets.