從您的Haskell程序中,您可以撥打ghc-mod。它是一個獨立的程序,它是能夠做到你想要什麼:
例如,在終端的命令ghc-mod browse Data.List
返回
all
and
any
break
concat
concatMap
cycle
...
如果你需要的類型,你可以使用ghc-mod browse -d Data.List
的功能。它返回:
all :: Foldable t => (a -> Bool) -> t a -> Bool
and :: Foldable t => t Bool -> Bool
any :: Foldable t => (a -> Bool) -> t a -> Bool
break :: (a -> Bool) -> [a] -> ([a], [a])
concat :: Foldable t => t [a] -> [a]
concatMap :: Foldable t => (a -> [b]) -> t a -> [b]
cycle :: [a] -> [a]
delete :: Eq a => a -> [a] -> [a]
...
可以安裝GHC-MOD與陰謀。要從Haskell程序中調用ghc-mod,您可以使用follow the answers to this SO question。首選的是使用shelly庫。
這裏是一個小的演示程序:
{-# LANGUAGE OverloadedStrings #-}
import Shelly
import qualified Data.Text as T
main :: IO()
main = shelly $ silently $ do
out <- run "ghc-mod" ["browse", "-d", "Data.List"]
-- lns will containes a list of lines with the function names and their types
let lns = T.lines out
-- Here we print out the number of functions and the first 5 functions
liftIO $ putStrLn $ show $ Prelude.length lns
liftIO $ mapM_ (putStrLn .T.unpack) $ take 5 lns
的可能的複製[如何在Haskell知道內建功能?](https://stackoverflow.com/questions/45463573/how-to-know- in-haskell-the-builtins-functions) – amalloy
你是什麼意思「不在Prelude」?你是不是在GHCi? – 4castle
要訪問任何類型的Haskell數據結構的模塊導入,您必須使用GHC API(請參見[這裏](https://downloads.haskell.org/~ghc/latest/docs/html/libraries/ghc -8.2.1/index.html)獲取GHC API文檔的最新版本,與您使用的任何版本可能有很大差異)。這是一個相當複雜和複雜的過程,可能有一種更簡單的方式來完成你正在努力完成的任何事情(但你沒有說明是什麼)。 – user2407038