Ich mag gerne wissen, warum Haskell dieseFehler in Haskell "kann nicht unendlich Typ erstellen"
perms xs = [ x:y | i <- [0..(length xs - 1)], x <- [xs!!i], y <- perms (takeOut i xs)]
akzeptiert aber nicht akzeptieren, dass:
perms xs = [ x:(perms y) | i <- [0..(length xs - 1)], x <- [xs!!i], y <- (takeOut i xs)]
Sie wirft
[1 von 1] Kompilierhaupt (abc.hs, interpretiert)
Occurs check: cannot construct the infinite type: t = [t] Expected type: t -> [t] Inferred type: [t] -> [[a]] In the second argument of `(:)', namely `(perms y)' In the expression: x : (perms y)
Ich kann verstehen, was es sagt, ich kann einfach nicht ist, warum der erste ist in Ordnung und der zweite ist nicht!
EDIT: Ah, natürlich habe ich auch
perms [] = [[]]
an der Spitze.
Dank
'(x, i) <- zip xs [0 ..]' anstelle von 'i <- [0 .. (Länge xs - 1)], x <- [xs !! i] 'ist viel besser –
Ja ist es! Vielen Dank! –