Haskell语言Prelude模块中函数readLn的用法及代码示例。
用法类型:
Read a => IO a
示例1:
源码:
main = do x <- getDouble
y <- getDouble
print (x+y)
getDouble :: IO Double
getDouble = readLn
输入:
12
输入:
4.34
输出:
16.34
示例2:
源码:
main = do x <- getList
print (product x)
getList :: IO [Int]
getList = readLn
输入:
[1,2,3,4]
输出:
24
示例3:
源码:
main = do x <- aaa
print x
aaa :: IO (Int,Int,[Int])
aaa = do x <- readLn
return (sum x, product x, x)
输入:
[1,3,5]
输出:
(9,15,[1,3,5])
注:本文由纯净天空筛选整理自 haskell readLn。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。