Skip to content

Instantly share code, notes, and snippets.

@bitwombat
Last active July 20, 2019 05:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bitwombat/7695bbdc8ef018a0a84aa0debd69664c to your computer and use it in GitHub Desktop.
Save bitwombat/7695bbdc8ef018a0a84aa0debd69664c to your computer and use it in GitHub Desktop.
Page475
module Page475 where
-- Ex 5
either' :: (a -> c) -> (b -> c) -> Either a b -> c
either' f g eab =
case eab of
Left a -> f a
Right b -> g b
-- Ex 6
rightVal :: Either a b -> b
rightVal (Right x) = x
eitherMaybe'' :: (b -> c) -> Either a b -> Maybe c
eitherMaybe'' f eab =
case eab of
Left _ -> Nothing
_ -> Just (either' (f . g (rightVal eab)) f eab)
where
g :: b -> a -> b
g b a = b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment