Haskell语言Prelude模块中函数readIO的用法及代码示例。
用法类型:
Read a => String -> IO a
示例1:
源码:
main = do x <- rList "[1,3,5,7]"
y <- rInt "5"
print (map (y*) x)
rList :: String -> IO [Int]
rList = readIO
rInt :: String -> IO Int
rInt = readIO
输出:
[5,15,25,35]
示例2:
源码:
main = do x <- aaa "[1,3,5,7]"
print x
aaa :: String -> IO (Int,Int,[Int])
aaa str = do x <- readIO str
return (sum x, product x, x)
输出:
(16,105,[1,3,5,7])
注:本文由纯净天空筛选整理自 haskell readIO。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。