我正在编写一个 Haskell 函数,它接受一个字符串列表并返回一个包含前两个字符串的列表作为结果作为元组。所以一个示例输出将是:
listtuple ["bride", "zilla", "crazy", "women"] = [("bride", "villa")]
listtuple ["basketball", "football"] = [("basketball", "football")]
我想这样接近它的方式:
listtuple :: Eq a => [Str a] -> [(Str a, Str a)]
listtuple xs = [(x,y) | x <- xs !! 0, y <- xs !! 1]
本质上,我认为我可以只选择列表的第一个和第二个索引中的元素,但我遇到了错误。这里有什么帮助吗?