gpt4 book ai didi

haskell - 找出函数属于哪个模块

转载 作者:行者123 更新时间:2023-12-02 21:19:28 25 4
gpt4 key购买 nike

在 ghci (haskell) 中,有一个命令可以告诉我函数属于哪个模块(在加载的模块中)。例如如果该函数被称为whichMod,那么它将按如下方式工作:

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

最佳答案

您需要 :i 命令(: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

正如您所建议的,它仅在该函数位于当前加载的模块中时才有效。

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

关于haskell - 找出函数属于哪个模块,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13722203/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com