だから私はhaskellを初めて使い、しばらくの間それで遊んでいます。すべてのリスト順列を出力する関数を機能させたいと考えています。私は2つの実装を書きました.1つはうまく機能し、もう1つはエラーを出しています. どんな助けでも素晴らしいでしょう。
これは最初の (実用的な) 実装です:
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)'
このエラーが発生する理由を誰かが説明できれば幸いです。ありがとう