Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

have ghci list all possible type class instances?

When ghc can't determine a concrete type class instance, you'll get a message like:

No instance for ...
  arising from a use of `it'
The type variable `a0' is ambiguous
Possible fix: add a type signature that fixes these type variable(s)
Note: there are several potential instances:
  (lists a few instances)
  ...plus 13 others
Possible fix: ...

Is there way to display all of the defined instances of a type class?

like image 263
ErikR Avatar asked Aug 20 '14 00:08

ErikR


1 Answers

You can use the :info command (shortened to :i) to do this:

> :i Num
class Num a where
  (+) :: a -> a -> a
  (*) :: a -> a -> a
  (-) :: a -> a -> a
  negate :: a -> a
  abs :: a -> a
  signum :: a -> a
  fromInteger :: Integer -> a
    -- Defined in ‘GHC.Num’
instance Num Integer -- Defined in ‘GHC.Num’
instance Num Int -- Defined in ‘GHC.Num’
instance Num Float -- Defined in ‘GHC.Float’
instance Num Double -- Defined in ‘GHC.Float’
like image 122
bheklilr Avatar answered Oct 23 '22 14:10

bheklilr