所以我是haskell的新手,我已经玩了一段时间了。我想让我的函数输出所有列表排列来工作。我写了 2 个实现,一个运行良好,另一个给我一个错误。任何帮助都是极好的。
这是第一个(工作)实现:
permute [] = [[]]
permute xs = [y| x <- xs, y <- map (x:) $ permute $ delete x xs]
这给了我一个错误:
permute [] = [[]]
permute xs = map (\x -> map (x:) $ permute $ delete x xs) xs
这是错误消息:
Occurs check: cannot construct the infinite type: t0 = [t0]
Expected type: [t0]
Actual type: [[t0]]
In the expression: map (x :) $ permute $ delete x xs
In the first argument of `map', namely
`(\ x -> map (x :) $ permute $ delete x xs)'
如果有人能解释我为什么会收到此错误,我将不胜感激。谢谢