我有以下代码.main获取stdin文本并对其进行排序g,然后f输出文本的输出并返回使用的提交的相应ExitCode内容exitWith.
我的问题是为什么这个程序在使用示例输入运行时,不会在输入第一行(test)之后立即终止,而只是在读取第二行(test2)之后失败?我想要发生的是g函数在返回后立即parse1返回,Left "left: test"而不是等到输入第二行.
码:
import System.Exit
import Control.Monad
import Data.Either
type ErrType = String
parse1 :: String -> Either ErrType Int
parse1 "test" = Left "left: test"
parse1 _ = Left "left"
parse2 :: String -> Either ErrType Char
parse2 s = Right (head s)
g :: String -> Either String String
g str =
let l1:l2:ls …Run Code Online (Sandbox Code Playgroud)