Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GHCi environment dump

Tags:

haskell

ghci

Is there is way in GHCi to basically get a state dump? By this I mean a list of:

  • All loaded operators along with it's precedence, associativity, and signature.
  • All loaded classes.
  • All loaded data, type, and newtype along with what classes they are instances of.
  • All loaded functions with it's signature, and the class they belong to if they do.

Assuming that this is possible, is it also possible to do this at runtime, say during an exception?

like image 930
Vanson Samuel Avatar asked Nov 09 '11 15:11

Vanson Samuel


1 Answers

:browse will give you most of this information. It shows

  • Type signatures for functions and operators.
  • Classes and their methods.
  • Data types, newtypes and type synonyms, with constructors if they are in scope.

Without any arguments, it shows this information for the currently loaded module. You can also specify a different module.

Prelude> :browse Control.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
...

To see more detail, including precedence and associativity for operators, as well as instances for a data type, use :info.

Prelude> :info (^)
(^) :: (Num a, Integral b) => a -> b -> a   -- Defined in GHC.Real
infixr 8 ^
Prelude> :info Bool
data Bool = False | True    -- Defined in GHC.Bool
instance Bounded Bool -- Defined in GHC.Enum
instance Enum Bool -- Defined in GHC.Enum
instance Eq Bool -- Defined in GHC.Base
instance Ord Bool -- Defined in GHC.Base
instance Read Bool -- Defined in GHC.Read

These commands are also available while debugging.

For more information, type :help or see the GHCi chapter of the GHC user's guide.

like image 53
hammar Avatar answered Oct 13 '22 05:10

hammar