所以我是新來的哈斯克爾,我一直在玩它一段時間了。我想讓我的函數輸出所有的列表排列工作。我寫了2個實現,其中一個很好,另一個給我一個錯誤。任何幫助都是極好的。haskell列表排列
這是第一個(工作)執行:
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)'
我如果有人能解釋我爲什麼會得到這個錯誤,我很感激。謝謝
注意這種使用'delete'的方法效率不高。 – leftaroundabout 2012-07-06 10:52:31
感謝您的支持,我正計劃檢查Data.List中的實現 – turingcomplete 2012-07-06 13:09:51