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'
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.
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.
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 .
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.
No, unfortunately. :-/
No you cannot have an answer under 30 characters.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With