[Haskell-cafe] Missing Functor instances in GHC 7?

Erik Hesselink hesselink at gmail.com
Fri Dec 10 10:13:31 CET 2010


On Fri, Dec 10, 2010 at 09:33, Simon Peyton-Jones <simonpj at microsoft.com> wrote:
> | Interestingly, if I import only Control.Applicative from within GHCi, it
> | does not find the instances defined in Control.Monad.Instances although
> | this module is imported in Control.Applicative. On the other hand, if I
> | write a file containing the line 'import Control.Applicative' and load
> | this file in GHCi then the instances from Control.Monad.Instances are
> | visible.
> |
> | Apparently, importing a module in GHCi differs from importing it in a
> | Haskell file and loading this into GHCi.
>
> I don't believe that should happen, depending on exactly what you mean by "importing a module in GHCi".

I see this as well. Using "import Control.Applicative" in ghci doesn't
seem to bring the instance into scope, while using ":m
+Control.Applicative" does. See the log below. Note that the instance
really isn't available, i.e. it's not a problem with :i.

GHCi, version 7.0.1: http://www.haskell.org/ghc/  :? for help
Loading package ghc-prim ... linking ... done.
Loading package integer-gmp ... linking ... done.
Loading package base ... linking ... done.
Loading package ffi-1.0 ... linking ... done.
Prelude> :i Functor
class Functor f where
  fmap :: (a -> b) -> f a -> f b
  (GHC.Base.<$) :: a -> f b -> f a
  	-- Defined in GHC.Base
instance Functor Maybe -- Defined in Data.Maybe
instance Functor [] -- Defined in GHC.Base
instance Functor IO -- Defined in GHC.Base
Prelude> import Control.Applicative
Prelude Control.Applicative> :i Functor
class Functor f where
  fmap :: (a -> b) -> f a -> f b
  (<$) :: a -> f b -> f a
  	-- Defined in GHC.Base
instance Functor ZipList -- Defined in Control.Applicative
instance Monad m => Functor (WrappedMonad m)
  -- Defined in Control.Applicative
instance Functor (Const m) -- Defined in Control.Applicative
instance Functor Maybe -- Defined in Data.Maybe
instance Functor [] -- Defined in GHC.Base
instance Functor IO -- Defined in GHC.Base
Prelude Control.Applicative> :m +Control.Applicative
Prelude Control.Applicative> :i Functor
class Functor f where
  fmap :: (a -> b) -> f a -> f b
  (<$) :: a -> f b -> f a
  	-- Defined in GHC.Base
instance Functor (Either a) -- Defined in Control.Monad.Instances
instance Functor ((->) r) -- Defined in Control.Monad.Instances
instance Functor ((,) a) -- Defined in Control.Monad.Instances
instance Functor ZipList -- Defined in Control.Applicative
instance Monad m => Functor (WrappedMonad m)
  -- Defined in Control.Applicative
instance Functor (Const m) -- Defined in Control.Applicative
instance Functor Maybe -- Defined in Data.Maybe
instance Functor [] -- Defined in GHC.Base
instance Functor IO -- Defined in GHC.Base
Prelude Control.Applicative>

Erik



More information about the Haskell-Cafe mailing list