作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
关注 haskell tutorial ,作者提供了以下实现 withFile 方法:
withFile' :: FilePath -> IOMode -> (Handle -> IO a) -> IO a
withFile' path mode f = do
handle <- openFile path mode
result <- f handle
hClose handle
return result
result
在
return
?不是提供的功能
f
已经返回
IO
从它的类型可以看出
Handle -> IO a
?
最佳答案
你说得对:f
已经返回 IO
,所以如果函数是这样写的:
withFile' path mode f = do
handle <- openFile path mode
f handle
hClose handle
介于两者之间,所以我们必须先存储结果:
result <- f handle
<-
摆脱
IO
.所以
return
放回去。
关于haskell - haskell 中如何实现 withFile,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8567044/
我在 Haskell 中实现了 withFile: withFile' :: FilePath -> IOMode -> (Handle -> IO a) -> IO a withFile' pat
关注 haskell tutorial ,作者提供了以下实现 withFile 方法: withFile' :: FilePath -> IOMode -> (Handle -> IO a) -> I
当给定由\n 分隔的文本输入文件时,该程序会产生我期望的输出: import System.IO main :: IO () main = do h IO [String] getlines h =
在 iOS 12.1 中,unarchiveObject(withFile:) 已被弃用。 如何将 NSKeyedUnarchiver.unarchiveObject(withFile: String
我是 Laravel 新手, 如果 laravel 对输入文本进行验证 然后当验证失败时,它会返回输入的文本值 return Redirect::back()->withInput() larave
我是一名优秀的程序员,十分优秀!