thkang
thkang

Reputation: 11533

How do I find information of an instance in ghci?

I can see data constructor and instances for, say Maybe in ghci:

Prelude Control.Applicative> :i Maybe
data Maybe a = Nothing | Just a     -- Defined in `Data.Maybe'
instance Eq a => Eq (Maybe a) -- Defined in `Data.Maybe'
instance Monad Maybe -- Defined in `Data.Maybe'
instance Functor Maybe -- Defined in `Data.Maybe'
instance Ord a => Ord (Maybe a) -- Defined in `Data.Maybe'
instance Read a => Read (Maybe a) -- Defined in `GHC.Read'
instance Show a => Show (Maybe a) -- Defined in `GHC.Show'
instance Applicative Maybe -- Defined in `Control.Applicative'
instance Alternative Maybe -- Defined in `Control.Applicative'

and I can see how Applicative typeclass defined in ghci, too:

Prelude Control.Applicative> :i Applicative
class Functor f => Applicative f where
  pure :: a -> f a
  (<*>) :: f (a -> b) -> f a -> f b
  (*>) :: f a -> f b -> f b
  (<*) :: f a -> f b -> f a
    -- Defined in `Control.Applicative'
instance Applicative [] -- Defined in `Control.Applicative'
instance Applicative ZipList -- Defined in `Control.Applicative'
instance Monad m => Applicative (WrappedMonad m)
  -- Defined in `Control.Applicative'
instance Applicative Maybe -- Defined in `Control.Applicative'
instance Applicative IO -- Defined in `Control.Applicative'
instance Applicative (Either e) -- Defined in `Control.Applicative'
instance Applicative ((->) a) -- Defined in `Control.Applicative'

but How can I find information about specific instances of a type, say instance Alternative Maybe ?

Upvotes: 3

Views: 1665

Answers (1)

sclv
sclv

Reputation: 38893

ghci doesn't have any commands that bring up the underlying source for functions and instances, although it would be neat if it did.

The way I find source of such things is to find them on hackage (for things in base, hoogle is the way to go). Then the haddocks include links to source from the documentation.

Upvotes: 4

Related Questions