Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Printing definitions of functions/classes in ghci with lambdabot

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.

like image 502
artella Avatar asked Feb 03 '26 04:02

artella


1 Answers

Lambdabot's src can't do this. It is based on a short list of function definitions that ships with lambdabot itself, cf. https://github.com/mokus0/lambdabot/blob/master/lambdabot/State/source. Consequently it sometimes lies, for example foldr is currently defined in ghc's libraries as

foldr k z = go
      where
        go []     = z
        go (y:ys) = y `k` go ys
like image 142
user3696868 Avatar answered Feb 04 '26 22:02

user3696868