Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to see the implemented code of a function of a module in haskell?

I am a newbie to Haskell and I know The Haskell standard library is split into modules, each of them contains functions and types that are somehow related and serve some common purpose. I would like to see the implementation(code) of those library functions.where can I see that ? is there any command in ghci so that I can see the implementation or provide me any resources to learn about modules. Thank you

like image 232
læran91 Avatar asked Nov 16 '17 09:11

læran91


1 Answers

Probably the most convenient way to do it, is use Hackage. You can for instance inspect the map function, by clicking Source on the right side of the function signature. This then will show the highlighted code fragment. For instance:

map :: (a -> b) -> [a] -> [b]
{-# NOINLINE [0] map #-}
  -- We want the RULEs "map" and "map/coerce" to fire first.
  -- map is recursive, so won't inline anyway,
  -- but saying so is more explicit, and silences warnings
map _ []     = []
map f (x:xs) = f x : map f xs

You can also use Hoogle to search functions by name or signature, and by clicking the results, you will be redirected to the relevant hackage page.

like image 123
Willem Van Onsem Avatar answered Oct 16 '22 02:10

Willem Van Onsem