I have found the definition for and, on the internet but I couldnt find the actual implementation of and. I did search for some sort of prelude haskell file on my computer but it didn't return anything which could be opened in a text editor.
You can use Hoogle to search for Haskell functions, like so:
http://www.haskell.org/hoogle/?hoogle=and
The function links take you to the library module where the function was defined, and in this case the link for and
takes us to here:
http://hackage.haskell.org/packages/archive/base/latest/doc/html/Prelude.html#v:and
You then click on the Source
link to the right of the function name and it takes you to the source of that function. For the case of and
it links us to 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'll see that and
actually has two definitions. One is the Standard Prelude definition, which is only enabled if you compile with the USE_REPORT_PRELUDE
flag, and the other is the definition the Prelude is usually compiled with, which is typically more optimized.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With