在haskell中,结合"case"和">> ="

qre*_*est 7 haskell case

我有很多代码的风格:

do
  x <- getSomething
  case x of
    this -> ...
    that -> ...
    other -> ...
Run Code Online (Sandbox Code Playgroud)

我将"x < - ..."和"case x of"行组合在一起以消除对变量的需求吗?

Ion*_*tan 6

您可以使用bind运算符>>=来管道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"
Run Code Online (Sandbox Code Playgroud)