【发布时间】:2011-12-19 20:21:35
【问题描述】:
按照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 可以看出?
【问题讨论】:
标签: haskell