ghci列出了所有可能的类型类实例吗? [英] have ghci list all possible type class instances?

查看:53
本文介绍了ghci列出了所有可能的类型类实例吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当ghc无法确定具体的类型类实例时,您会收到类似以下消息:

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?

推荐答案

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

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’

这篇关于ghci列出了所有可能的类型类实例吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆