Skip to content

Inconsistent import of instances in GHCi

Issuing import M in GHCi does not bring the same instances into scope as issuing :m + M and loading a file that contains import M do.

For example, the module Control.Applicative imports Control.Monad.Instances which defines a Functor instance for ((->) r). The following GHCi session demonstrates that this instance is not in scope after issuing an import command in GHCi but it is in scope after issuing an :m + command. It is also in scope after loading a file that imports Control.Applicative.

Prelude> fmap id id ()

<interactive>:1:1:
    No instance for (Functor ((->) ()))
      arising from a use of `fmap'
    Possible fix: add an instance declaration for (Functor ((->) ()))
    In the expression: fmap id id ()
    In an equation for `it': it = fmap id id ()
Prelude> import Control.Applicative
Prelude Control.Applicative> fmap id id ()

<interactive>:1:1:
    No instance for (Functor ((->) ()))
      arising from a use of `fmap'
    Possible fix: add an instance declaration for (Functor ((->) ()))
    In the expression: fmap id id ()
    In an equation for `it': it = fmap id id ()
Prelude Control.Applicative> :m + Control.Applicative
Prelude Control.Applicative> fmap id id ()
()

I expected that issuing an import command in GHCi has the same effect as issuing an :m + command or loading a file with an import statement.

Trac metadata
Trac field Value
Version 7.0.1
Type Bug
TypeOfFailure OtherFailure
Priority normal
Resolution Unresolved
Component GHCi
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