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

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

有没有办法显示类型类的所有已定义实例?

最佳答案

您可以使用 :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’

关于haskell - ghci 列出所有可能的类型类实例吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25395091/

相关文章:

Haskell:Num 是如何保存的?

recursion - 定义递归依赖字段时 Coq 类型类出现问题

haskell - 如何实现 Haskell 扩展?

haskell - Haskell 中 => 符号是什么意思?

haskell - 如何使类型成为 Eq 的实例

Haskell - 计算列表中某个值出现的次数

haskell - 为什么这个 Haskell 在扩展时会提示类型不明确?

haskell - "No instance for"错误

javascript - 如何用急速移除属性

haskell - 如何处理不完整的 JSON/Record 类型(IE 缺少我稍后会填写的必填字段)?