如何在Haskell/GHCi中查看函数的定义? [英] How can I view the definition of a function in Haskell/GHCi?

查看:111
本文介绍了如何在Haskell/GHCi中查看函数的定义?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将Haskell 2010.1.0.0.1与GHC 6一起使用.在GHCi提示符下键入:t,后跟一个函数的名称,向我们展示该函数的类型.有没有办法查看函数定义?

I'm using Haskell 2010.1.0.0.1 with GHC 6. Typing :t at the GHCi prompt followed by the name of a function shows us the type of the function. Is there a way to view the function definition as well?

推荐答案

当前不是.

最接近您想要的命令是:info

The closest command to what you want is :info

:信息名称...

:info name ...

显示有关给定名称的信息.例如,如果name是一个类,则将打印类方法及其类型;否则,将显示类方法.如果name是类型构造函数,则将打印其定义;如果name是一个函数,则将打印其类型.如果已从源文件中加载名称,则GHCi还将在源文件中显示其定义的位置.

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.

对于类型和类,GHCi还汇总了提及它们的实例.为了避免显示不相关的信息,仅在以下情况下显示一个实例:(a)它的标题提到名称,并且(b)由于:load或:模块命令.

For types and classes, GHCi also summarises instances that mention them. To avoid showing irrelevant information, an instance is shown only if (a) its head mentions name, and (b) all the other things mentioned in the instance are in scope (either qualified or otherwise) as a result of a :load or :module commands.

像这样:

Prelude> :info ($)
($) :: (a -> b) -> a -> b   -- Defined in GHC.Base
infixr 0 $

不过,您可以在Hackage上查看haddock工具生成的标识符的来源.

You can though, see the source for identifiers generated by the haddock tool, on Hackage.

  1. 查找黑客模块
  2. 点击在源链接上
  1. Look up the module on Hackage
  2. Click on the source link

请注意,在#haskell IRC频道上的lambdabot中,?src" 是有效的命令,它可以满足您的期望.

Note that "?src" is a valid command in lambdabot, on the #haskell IRC channel, and does what you'd expect.

> ?src ($)
> f $ x = f x

这篇关于如何在Haskell/GHCi中查看函数的定义?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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