How can I see the implementation code for "and"?

I found a definition for and, on the Internet, but I could not find the actual implementation of and. I was looking for some kind of prekey haskell file on my computer, but it did not return anything that could be opened in a text editor.

+7
source share
3 answers

You can use Hoogle to search for Haskell functions, for example:

http://www.haskell.org/hoogle/?hoogle=and

The links to the functions pass you to the library module where the function was defined, in which case the link for and will lead us here:

http://hackage.haskell.org/packages/archive/base/latest/doc/html/Prelude.html#v:and

Then click the Source link to the right of the function name and go to the source of this function. For the case of and he binds us here:

http://hackage.haskell.org/packages/archive/base/latest/doc/html/src/GHC-List.html#and

 and :: [Bool] -> Bool or :: [Bool] -> Bool #ifdef USE_REPORT_PRELUDE and = foldr (&&) True or = foldr (||) False #else and [] = True and (x:xs) = x && and xs or [] = False or (x:xs) = x || or xs #endif 

You will see that and has two definitions. One of them is the definition of the standard prelude, which is only allowed when compiling with the USE_REPORT_PRELUDE flag, and the other is the definition that is usually compiled into Prelude, which is usually more optimized.

+19
source

You cannot expect to find the source code in your local Haskell distribution, which is probably the Haskell platform. Instead, go to Hoogle and search for the function. One of the ways you want is to search by his name, and , go to his haddock, and then click "source."

In Hoogle, you can also search by type, i.e. [Bool] -> Bool , which you'll probably do quite often.

+2
source

Take a look at http://www.haskell.org/onlinereport/standard-prelude.html

and defined as foldr (&&) True .

+1
source

All Articles