DEV Community

I can't understand the twiceOptional function from Data61 fp course.

Anton on December 14, 2018

-- Here's what we've got with Optional data Optional a = Full a | Empty deriving Show (Eq, Show) mapOptional :: (a -> b) -> Optinoal ...
Collapse
 
jvanbruegge profile image
Jan van Brügge
  1. You are wrong about the partial application, it is like this (note the parenthesis):
twiceOptional (+) (Full 1) (Full 2) = (applyOptional . mapOptional (+)) (Full 1) (Full 2)
  1. Because when bindOptional encounters an Empty it does not evaluate further and just returns Empty