I don’t quite understand how functions behave when working with applicative functors.
Here’s an example:
ghci> (&&) <$> Just False <*> undefined
*** Exception: Prelude.undefined
CallStack (from HasCallStack):
undefined, called at <interactive>:6:25 in interactive:Ghci6
But if we don’t use the Maybe context, then everything works as expected:
ghci> (&&) False undefined
False
Accordingly, the question is – why does this happen and is it possible to somehow avoid it?
How to ensure such behavior that if (&&) <$> Just False
is encountered, the result of the function would immediately be Just False
?
New contributor
Leonid is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.