如何在 GHCi 中打印类型的构造函数?
How to print the constructors of a type in GHCi?
使用:t
我可以打印表达式的类型。但是我如何查看该类型的构造函数呢?在 emacs 的 Haskell 模式下也有快捷方式吗?
这似乎是一个基本的东西,但我找不到。也许我只是在搜索错误的术语...
一般来说,无需查看文档即可查看打印类型定义的最简单方法是什么。
:info
,或者 :i
,就是您想要的:
>>> :i Either
data Either a b = Left a | Right b -- Defined in ‘Data.Either’
... plus all of Either's instances
:info name ...
Displays information about the given name(s). For example, if name is
a class, then the class methods and their types will be printed; if
name is a type constructor, then its definition will be printed; if
name is a function, then its type will be printed. If name has been
loaded from a source file, then GHCi will also display the location of
its definition in the source.
Haskell-Emacs 中的模式有 haskell-process-do-info
(source), for which one Haskell on Emacs Tutorial 建议设置键绑定 C-c C-n C-i
.
(defun haskell-process-do-info (&optional prompt-value)
"Print info on the identifier at point.
If PROMPT-VALUE is non-nil, request identifier via mini-buffer."
...
)
使用:t
我可以打印表达式的类型。但是我如何查看该类型的构造函数呢?在 emacs 的 Haskell 模式下也有快捷方式吗?
这似乎是一个基本的东西,但我找不到。也许我只是在搜索错误的术语...
一般来说,无需查看文档即可查看打印类型定义的最简单方法是什么。
:info
,或者 :i
,就是您想要的:
>>> :i Either
data Either a b = Left a | Right b -- Defined in ‘Data.Either’
... plus all of Either's instances
:info name ...
Displays information about the given name(s). For example, if name is a class, then the class methods and their types will be printed; if name is a type constructor, then its definition will be printed; if name is a function, then its type will be printed. If name has been loaded from a source file, then GHCi will also display the location of its definition in the source.
Haskell-Emacs 中的模式有 haskell-process-do-info
(source), for which one Haskell on Emacs Tutorial 建议设置键绑定 C-c C-n C-i
.
(defun haskell-process-do-info (&optional prompt-value)
"Print info on the identifier at point.
If PROMPT-VALUE is non-nil, request identifier via mini-buffer."
...
)