内容简介:http://stackoverflow.com/questions/8540999/extracting-a-maybe-value-in-io
给出以下内容:
> (liftM2 fromMaybe) (ioError $userError "OOPS") (return $Just "ok")
ghci给我
*** Exception: user error (OOPS)
当然,从Mayay可以正常工作:
> (liftM2 fromMaybe) (return $"not me") (return $Just "ok") "ok"
但是,IO操作似乎正在执行,然后被丢弃:
> (liftM2 fromMaybe) (putStrLn "computing.." >> "discarded") (return $Just "ok") computing.. "ok"
为什么会发生这种情况?有没有办法使IO monad lazier?
具体来说,给定值:: IO(也许a)一个(干净,简洁)的方式
result <- (liftM2 fromMaybe) err value
并解压缩结果或相应地引发IOError?
我不知道制作IO懒惰是这里的正确方向.你似乎想做的是首先得到可能,然后消除它.这可以写几种方法,这里有一个选项:
test :: IO (Maybe a) -> IO a test = (>>= maybe (ioError $userError "oops") return)
http://stackoverflow.com/questions/8540999/extracting-a-maybe-value-in-io
以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网
猜你喜欢:本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
Flexible Rails
Peter Armstrong / Manning Publications / 2008-01-23 / USD 44.99
Rails is a fantastic tool for web application development, but its Ajax-driven interfaces stop short of the richness you gain with a tool like Adobe Flex. Simply put, Flex is the most productive way t......一起来看看 《Flexible Rails》 这本书的介绍吧!