Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/haskell/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Haskell 将匿名条件与IO混合的最简单方法_Haskell - Fatal编程技术网

Haskell 将匿名条件与IO混合的最简单方法

Haskell 将匿名条件与IO混合的最简单方法,haskell,Haskell,如何避免像doesExist=cond这样的样板任务 (putStrLn$path++“存在”) (putStrLn$path++“不存在”) 条件b c a=如果a,则b,否则c LambdaCase适用于以下情况: {-# LANGUAGE LambdaCase #-} import System.Directory import System.Environment main = do path:_ <- getArgs doesDirectoryExist p

如何避免像
doesExist=cond这样的样板任务
(putStrLn$path++“存在”)
(putStrLn$path++“不存在”)
条件b c a=如果a,则b,否则c

LambdaCase
适用于以下情况:

{-# LANGUAGE LambdaCase #-}

import System.Directory
import System.Environment

main = do
  path:_ <- getArgs    

  doesDirectoryExist path >>= \case
    True -> putStrLn $ path ++ " Exists"
    _    -> putStrLn $ path ++ " Does not exist"
{-#语言LambdaCase}
导入系统目录
导入系统。环境
main=do
路径:\u>=\ case
True->putStrLn$path++“存在”
_->putStrLn$path++“不存在”
或与“如果”相同:


顺便说一句,
cond
flip bool
如果您导入
Data.bool
{-# LANGUAGE LambdaCase #-}

import System.Directory
import System.Environment

main = do
  path:_ <- getArgs    

  doesDirectoryExist path >>= \case
    True -> putStrLn $ path ++ " Exists"
    _    -> putStrLn $ path ++ " Does not exist"
doesDirectoryExist path >>= \x ->
 if x then (putStrLn "Exists") else putStrLn ("Does not")