I have a lot of code of the style:
do
x <- getSomething
case x of
this -> ...
that -> ...
other -> ...
Any way of me combining the "x <- ..." and "case x of" lines to eliminate the need for a variable?
You could use the bind operator >>=
to pipe the x
.
import System.Environment (getArgs)
main :: IO ()
main = getArgs >>= process
where process ["xxx"] = putStrLn "You entered xxx"
process ["yyy"] = putStrLn "You entered yyy"
process _ = putStrLn "Error"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With