标签: haskell
如何将列表[[a]]转换为元组([a], [a])?
[[a]]
([a], [a])
示例:
输入:[[1], [2,3,4]]
[[1], [2,3,4]]
输出:([1], [2,3,4])
([1], [2,3,4])
答案 0 :(得分:9)
模式匹配怎么样?
convert :: [[a]] -> Maybe ([a], [a]) convert [x, y] = Just (x, y) convert _ = Nothing
Maybe只是为了处理我们列表中没有两个元素的情况。
Maybe