【发布时间】:2018-03-31 04:53:30
【问题描述】:
考虑这个程序:
module test
import Effects
import Effect.StdIO
(>>==) : Maybe a -> Lazy (a -> Maybe b) -> Maybe b
(>>==) Nothing (Delay map) = Nothing
(>>==) (Just x) (Delay map) = map x
nothing : String -> Eff (Maybe String) [STDIO]
nothing s = do
putStrLn s
pure Nothing
func : Maybe String -> String -> Maybe String
func Nothing _ = Nothing
func (Just s) t = Just (s ++ t)
test : Eff () [STDIO]
test = do
let m = !(nothing "a") >>== (func !(nothing "b"))
putStrLn "end"
main : IO ()
main = run test
由于>>== 的右侧被声明为惰性并且!(nothing "a") 返回Nothing,我希望>>== 的右侧不会被评估。
但实际上它确实得到了评估,我不明白为什么......
更广泛地说,我正在尝试连接可能返回的 Eff 计算,并在我得到第一个 Nothing 时停止执行
【问题讨论】:
标签: monads lazy-evaluation idris