Unwrapping a monad

后端 未结 3 1367
Happy的楠姐
Happy的楠姐 2020-12-04 02:06

Given the below program, I am having issues dealing with monads.

module Main 
where
import System.Environment
import System.Directory
import System.IO
import         


        
3条回答
  •  情歌与酒
    2020-12-04 02:46

    Use case.

    main = do
        ...
        case csv_data of
            Left  err -> {- whatever you're going to do with an error -- print it, throw it as an exception, etc. -}
            Right csv -> printCSV csv
    

    The either function is shorter (syntax-wise), but boils down to the same thing.

    main = do
        ...
        either ({- error condition function -}) printCSV csv_data
    

提交回复
热议问题