GHCi Reset

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

  • All loaded operators along with it have priority, associativity and signature.
  • All loaded classes.
  • All loaded data, type and type newtype, together with which classes they are instances.
  • All loaded functions with its signatures and the class to which they belong, if they do.

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

+6
source share
2 answers

:browse will provide you with most of this information. He shows

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

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

 Prelude> :browse Control.Applicative class (Functor f) => Applicative f where pure :: a -> fa (<*>) :: f (a -> b) -> fa -> fb (*>) :: fa -> fb -> fb (<*) :: fa -> fb -> fa ... 

To find out details, including priority and associativity for statements, 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 during debugging.

For more information, type :help or see the GHCi chapter of the GHC User Guide .

+4
source

There are ways to get this information. The problem is that, as far as I know, there is no way to filter exactly how you want, but in any case, this:

  • If you want to see all the identifiers, including the classes, operators, constructors and types that are currently defined in ghci, just click on the tab when you point the cursor to spaces.

  • If you want to know the priority and associativity of the * operator, just use

     :i * 
  • If you want to see which classes of M are an instance of just used

     :i M 
  • If you want to see the signature of f , just use

     :if 

    If you write :set -fbreak-on-exception , then ghci will break, and then crash when an exception is thrown, and then you can use all of the above commands during the exception.

+1
source

Source: https://habr.com/ru/post/901124/


All Articles