在ghci(haskell)中有一个命令可以告诉我一个函数属于哪个模块(加载的模块中)。例如如果该函数被称为whichMod,那么它将如下工作:
Prelude>whichMod take
Prelude
Prelude>whichMod sort
Data.List
答案 0 :(得分:5)
您需要: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
正如您所建议的那样,只有当函数位于当前加载的模块中时才有效。
请注意,系统会告诉您最初定义该功能的模块。 take
在GHC.List
中定义(至少在我的ghc副本中),但是从前奏中重新导出。您没有被告知从哪个模块导入它。
答案 1 :(得分:5)
是的,存在该功能:
Prelude> :! hoogle sort
Data.List sort :: Ord a => [a] -> [a]
Data.List sortBy :: (a -> a -> Ordering) -> [a] -> [a]
Data.ByteString sort :: ByteString -> ByteString
Data.ByteString.Char8 sort :: ByteString -> ByteString
Data.Sequence sort :: Ord a => Seq a -> Seq a
package sort-by-pinyin
Data.Sequence sortBy :: (a -> a -> Ordering) -> Seq a -> Seq a
GHC.Exts sortWith :: Ord b => (a -> b) -> [a] -> [a]
package sorty
package cabal-sort
package external-sort
Data.Graph.Inductive.Internal.Heap heapsort :: Ord a => [a] -> [a]
package heapsort
package natural-sort
package NaturalSort
Data.Graph topSort :: Graph -> [Vertex]
Data.Graph.Inductive.Query.DFS topsort :: Graph gr => gr a b -> [Node]
Data.Graph.Inductive.Query.DFS topsort' :: Graph gr => gr a b -> [a]
Data.Sequence unstableSort :: Ord a => Seq a -> Seq a
Data.Sequence unstableSortBy :: (a -> a -> Ordering) -> Seq a -> Seq a
Prelude> _
您可以在“〜/ .ghci”配置文件中定义别名
:def hoogle \str -> return $ ":! hoogle \"" ++ str ++ "\""
然后,你可以写
Prelude> :hoogle sort
Data.List sort :: Ord a => [a] -> [a]
Data.List sortBy :: (a -> a -> Ordering) -> [a] -> [a]
Data.ByteString sort :: ByteString -> ByteString
Data.ByteString.Char8 sort :: ByteString -> ByteString
Data.Sequence sort :: Ord a => Seq a -> Seq a
package sort-by-pinyin
Data.Sequence sortBy :: (a -> a -> Ordering) -> Seq a -> Seq a
GHC.Exts sortWith :: Ord b => (a -> b) -> [a] -> [a]
package sorty
package cabal-sort
package external-sort
Data.Graph.Inductive.Internal.Heap heapsort :: Ord a => [a] -> [a]
package heapsort
package natural-sort
package NaturalSort
Data.Graph topSort :: Graph -> [Vertex]
Data.Graph.Inductive.Query.DFS topsort :: Graph gr => gr a b -> [Node]
Data.Graph.Inductive.Query.DFS topsort' :: Graph gr => gr a b -> [a]
Data.Sequence unstableSort :: Ord a => Seq a -> Seq a
Data.Sequence unstableSortBy :: (a -> a -> Ordering) -> Seq a -> Seq a
Prelude> _
答案 2 :(得分:3)
Prelude> :info take
take :: Int -> [a] -> [a] -- Defined in `GHC.List'