,
Monad -> Monad
Monad -> Pure
Pure -> Monad
Pure -> Pure
Monad -> Monad (>>=), , , |>= Pure -> Monad, Monad -> Pure . , - .
Monad -> Monad >>= m a -> (a -> m b) -> m b
Monad -> Pure >|= m a -> (a -> b) -> m b
Pure -> Monad |>= a -> (a -> m b) -> m b
Pure -> Pure ||= (a -> b) -> (b -> c) -> (a -> c)
, > "monad" | "", =, "to function". , :
import Data.Char (toUpper)
import Control.Monad (liftM)
infixl 1 |>=
(|>=) :: Monad m => a -> (a -> m b) -> m b
a |>= b = b a
infixl 1 >|=
(>|=) :: Monad m => m a -> (a -> b) -> m b
a >|= b = liftM b a
infixr 9 ||=
(||=) :: (a -> b) -> (b -> c) -> a -> c
a ||= b = b . a
test :: IO ()
test =
getLine >|=
filter (/= 't') ||=
map toUpper >>=
putStrLn
> test
testing
ESING
>
test :: IO ()
test =
getLine >|=
filter (/= 't') >|=
map toUpper >>=
putStrLn
But the added combination ||>would allow you to actually compose those functions that have different implementations under the hood than feed them through monadic actions.
However, I still urge you to use the idiomatic way to do this using fmap, make notation and temporary variables. This will be much clearer to anyone looking at the code, and this will include you in 2 months.
source
share