her.esy.fun/src/posts/0010-Haskell-Now/maybe_monad_3.hs
Yann Esposito (Yogsototh) 3f403f946b
Progress
2019-12-26 17:27:19 +01:00

21 lines
536 B
Haskell

deposit :: (Num a) => a -> a -> Maybe a
deposit value account = Just (account + value)
withdraw :: (Num a,Ord a) => a -> a -> Maybe a
withdraw value account = if (account < value)
then Nothing
else Just (account - value)
eligible :: (Num a, Ord a) => a -> Maybe Bool
eligible account =
deposit 100 account >>=
withdraw 200 >>=
deposit 100 >>=
withdraw 300 >>=
deposit 1000 >>
return True
main = do
print $ eligible 300 -- Just True
print $ eligible 299 -- Nothing