找出功能属于哪个模块 [英] Finding out which module a function belongs to

查看:91
本文介绍了找出功能属于哪个模块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在ghci(haskell)中,有一个命令会告诉我函数属于哪个模块(在已加载的模块中).例如如果该函数名为whichMod,则它将按以下方式工作:

In ghci (haskell) is there a command which will tell me which module (out of the loaded modules) a function belongs to. e.g. if the function is called whichMod, then it would work as follows :

Prelude>whichMod take
Prelude
Prelude>whichMod sort
Data.List

推荐答案

您需要:i命令(:info的缩写).

You want the :i command (short for :info).

Prelude> :i take
take :: Int -> [a] -> [a]   -- Defined in GHC.List
Prelude> :i sort

Top level: Not in scope: `sort'
Prelude> :m +Data.List
Prelude Data.List> :i sort
sort :: Ord a => [a] -> [a]     -- Defined in Data.List

如您所建议,仅当该功能在当前加载的模块中时,该功能才起作用.

As you suggest, it only works if the function is in a currently loaded module.

请注意,系统会告知您该函数最初在哪个模块中定义. takeGHC.List中定义(至少在我的ghc副本中),但从前奏中重新导出.您不会被告知是从哪个模块导入的.

Note that you are told which module the function is originally defined in. e.g. take is defined in GHC.List (at least in my copy of ghc), but re-exported from the prelude. You are not told which module(s) you imported it from.

这篇关于找出功能属于哪个模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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