【发布时间】:2013-12-07 02:33:00
【问题描述】:
无论如何我可以将字符串读取为整数吗?
例如阅读
triangle = ["1"
,"2 3"
,"4 5 6"]
作为[[1],[2,3],[4,5,6]]
convertToInt :: [String] -> [[Int]]
convertToInt [] = []
convertToInt (x:xs) = **(somehow convert x to list of ints)** : convertToInt xs
不知道如何进行,是否有任何内置函数?
编辑:谢谢!这是解决方案
convertToInt :: [String] -> [[Int]]
convertToInt [] = []
convertToInt (x:xs) = (map read (words x)) : convertToInt xs
【问题讨论】:
标签: haskell