Skip to content

Instantly share code, notes, and snippets.

@shigemk2
Created September 2, 2015 12:04
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 shigemk2/b1eec3957b11a23cd3a6 to your computer and use it in GitHub Desktop.
Save shigemk2/b1eec3957b11a23cd3a6 to your computer and use it in GitHub Desktop.
-- オレオレバインド(>>=)の実装
applyMaybe :: Maybe a -> (a -> Maybe b) -> Maybe b
applyMaybe Nothing f = Nothing
applyMaybe (Just x) f = f x
main = do
print $ Just 3 `applyMaybe` \ x -> Just (x+1)
print $ Just "smile" `applyMaybe` \ x -> Just (x ++ " :)")
print $ Nothing `applyMaybe` \ x -> Just (x+1)
print $ Nothing `applyMaybe` \ x -> Just (x ++ " :)")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment