有ghci列出所有可能的类型类实例?

时间:2014-08-20 00:39:16

标签: haskell typeclass ghci

当ghc无法确定具体类型类实例时,您将收到如下消息:

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: ...

是否可以显示类型类的所有已定义实例?

1 个答案:

答案 0 :(得分:10)

您可以使用:info命令(缩写为:i)来执行此操作:

> :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’