问题描述
在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.
请注意,系统会告知您该函数最初在哪个模块中定义. take
在GHC.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.
这篇关于找出功能属于哪个模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!