plutus-pioneer-program/code/week04/src/Week04/Monad.hs

27 lines
797 B
Haskell
Raw Normal View History

2021-04-27 09:14:58 +02:00
module Week04.Monad where
-- (>>=) :: IO a -> (a -> IO b) -> IO b
-- bindMaybe :: Maybe a -> (a -> Maybe b) -> Maybe b
-- bindEither :: Either String a -> (a -> Either String b) -> Either String b
-- bindWriter :: Writer a -> (a -> Writer b) -> Writer b
--
-- return :: a -> IO a
-- Just :: a -> Maybe a
-- Right :: a -> Either String a
-- (\a -> Writer a []) :: a -> Writer a
threeInts :: Monad m => m Int -> m Int -> m Int -> m Int
threeInts mx my mz =
mx >>= \k ->
my >>= \l ->
mz >>= \m ->
let s = k + l + m in return s
threeInts' :: Monad m => m Int -> m Int -> m Int -> m Int
threeInts' mx my mz = do
k <- mx
l <- my
m <- mz
let s = k + l + m
return s