3

How can I view the source definitions in ghci (with lambdabot 2.5 GHCi on Acid) of functions/classes etc defined in my project or cabal dependencies? For example suppose I have :

module Main where
import System.Random

gen = (random (mkStdGen 0)) :: (Bool,StdGen)

myadd :: Int -> Int
myadd x = 2 * x

main = do
  print "finished"

Then I can get information on myadd and random but I cannot print the source. Here is what I can do in ghci (with lambdabot) :

*Main GOA> :src foldr
 foldr f z []     = z
foldr f z (x:xs) = f x (foldr f z xs)
*Main GOA> :i myadd
myadd :: Int -> Int     -- Defined at test.hs:7:1
*Main GOA> :src myadd
 Source not found. I don't think I can be your friend on Facebook anymore.
*Main GOA> :i random
class Random a where
  ...
  random :: RandomGen g => g -> (a, g)
  ...
    -- Defined in ‘System.Random’
*Main GOA> :src random
 Source not found. Listen, broccoli brains, I don't have time to listen to this trash.

lambdabot seems to be able to print the definitions of foldr but not functions defined in the project (myadd) or functions in the cabal depedencies (random).

Is it possible for me to print out the definitions of things like myadd and random, using some feature of lambdabot? I know you can use Hoogle for random but I want to specifically know if there is any way to use ghci or lambdabot to print out the source definitions.

[EDIT]

Since posting I discovered Emacs/Inferior Haskell processes and some of the functionality theirin seems to achieve some of the above.

4

1 回答 1

1

Lambdabotsrc无法做到这一点。它基于 lambdabot 本身附带的函数定义的简短列表,参见。https://github.com/mokus0/lambdabot/blob/master/lambdabot/State/source。因此它有时存在,例如foldr当前在 ghc 的库中定义为

foldr k z = go
      where
        go []     = z
        go (y:ys) = y `k` go ys
于 2014-06-01T13:44:55.557 回答