How can this function return true?
foldr (||) False [True,undefined]
=> True
The first fold looks like this:
undefined || True
, which should return an error
So im guessing haskell gives priority to the lazyness of the OR function over doing the folds step by step. Finds a True
on the way and returns that before starting the fold
Is this correct? In that case, does haskell always give priority to a lazy function over the non lazy ones? I believe that is the definition for being lazy but it seems like that can change the answer to make it wrong
According to the definition of foldr
,
foldr (||) False [True,undefined]
=
True || foldr (||) False [undefined]
According to the definition of (||)
,
True || _ = True
so there's no need to know the value of the right hand expression to know the answer.
foldr
does not do steps on its own. The process is driven by the demands of the reducer function.
edit: Nothing funny's going on. Each evaluation step is straightforwardly done according to the definitions involved.
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