I can get the source of functions from prelude:
lambdabot> src foldr
foldr f z [] = z
foldr f z (x:xs) = f x (foldr f z xs)
but I can’t get the source from other modules:
lambdabot> src flatten
Source not found. Maybe if you used more than just two fingers...
lambdabot> hoogle flatten
Data.Tree flatten :: Tree a -> [a]
Data.Graph flattenSCC :: SCC vertex -> [vertex]
Data.Graph flattenSCCs :: [SCC a] -> [a]
lambdabot> src Data.Tree flatten
Source not found. Just try something else.
lambdabot> src Data.Tree.flatten
Source not found. Have you considered trying to match wits with a rutabaga?
lambdabot> src Tree flatten
Source not found. And you call yourself a Rocket Scientist!
lambdabot> src Tree.flatten
Source not found. Just try something else.
How can I do this?
You can’t really do this. lambdabot uses a hard-wired file full of name->source mappings; it doesn’t look up the source of an identifier in a particularly principled way.
The best you can do in general is
:i fooin ghci to find out which module an identifier comes from, and then look up the source of that module (say, with Hoogle, which typically links to pages with source links).