Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ghci show only typeclass methods

Tags:

haskell

ghci

In ghci you can run the :info command to learn about the methods defined on a type class, as well as see instances of that type class.

For example, :info Eq outputs

class Eq a where
  (==) :: a -> a -> Bool
  (/=) :: a -> a -> Bool
    -- Defined in `GHC.Classes'

as well as many lines of the instances

instance (Eq k, Eq a) => Eq (Map k a)
  -- Defined in `containers-0.5.0.0:Data.Map.Base'
instance Eq a => Eq (Maybe a) -- Defined in `Data.Maybe'
...

Is there a way, in ghci, to just output the methods defined in the type class without also outputting all the instances? In other words, I would like a ghci command to output only this:

class Eq a where
  (==) :: a -> a -> Bool
  (/=) :: a -> a -> Bool
    -- Defined in `GHC.Classes'
like image 226
apolune Avatar asked Apr 29 '14 21:04

apolune


People also ask

How do you define Typeclass in Haskell?

What's a typeclass in Haskell? A typeclass defines a set of methods that is shared across multiple types. For a type to belong to a typeclass, it needs to implement the methods of that typeclass. These implementations are ad-hoc: methods can have different implementations for different types.

How do I leave a stack GHCi?

Quits GHCi. You can also quit by typing control-D at the prompt. Attempts to reload the current target set (see :load ) if any of the modules in the set, or any dependent module, has changed.

What does EQ mean Haskell?

The Eq class defines equality ( == ) and inequality ( /= ). All the basic datatypes exported by the Prelude are instances of Eq , and Eq may be derived for any datatype whose constituents are also instances of Eq . The Haskell Report defines no laws for Eq .

What are Typeclasses used for?

A typeclass is a sort of interface that defines some behavior. If a type is a part of a typeclass, that means that it supports and implements the behavior the typeclass describes. A lot of people coming from OOP get confused by typeclasses because they think they are like classes in object oriented languages.


1 Answers

No, unfortunately. :-/

No you cannot have an answer under 30 characters.

like image 179
luqui Avatar answered Nov 05 '22 21:11

luqui