Wie kombiniert man die Buchstaben von zwei strings in haskell

Ich Lerne Haskell und nach dem guide auf http://learnyouahaskell.com/starting-out. Ich bin an dem Punkt, wo es gezeigt:

ghci> let nouns = ["hobo","frog","pope"]  
ghci> let adjectives = ["lazy","grouchy","scheming"]  
ghci> [adjective ++ " " ++ noun | adjective <- adjectives, noun <- nouns]  
["lazy hobo","lazy frog","lazy pope","grouchy hobo","grouchy frog",  
"grouchy pope","scheming hobo","scheming frog","scheming pope"]   

Was möchte ich erreichen, es ist etwas ähnliches, aber die Kombination der Buchstaben enthalten in beiden strings, und da die strings sind im wesentlichen Listen von char in Haskell, das ist, was ich versucht habe:

 [x ++ ' ' ++ y | x <- "ab", y <- "cd"]

Aber der compiler beschwert sich:

Prelude> [y ++ ' ' ++ y | x <- "abd", y <- "bcd"]

<interactive>:50:2:
    Couldn't match expected type ‘[a]’ with actual type Char
    Relevant bindings include it :: [[a]] (bound at <interactive>:50:1)
    In the first argument of ‘(++)’, namely y
    In the expression: y ++ ' ' ++ y

<interactive>:50:7:
    Couldn't match expected type ‘[a]’ with actual type Char
    Relevant bindings include it :: [[a]] (bound at <interactive>:50:1)
    In the first argument of ‘(++)’, namely ' '
    In the second argument of ‘(++)’, namely ' ' ++ y
    In the expression: y ++ ' ' ++ y

<interactive>:50:14:
    Couldn't match expected type ‘[a]’ with actual type Char
    Relevant bindings include it :: [[a]] (bound at <interactive>:50:1)
    In the second argument of ‘(++)’, namely y
    In the second argument of ‘(++)’, namely ' ' ++ y

Habe ich eine Reihe von versuchen, wie das einwickeln der Ausdruck in Klammern ein, um eine Liste, so verändert sich der Raum, der einen String anstatt einer char... Wie bekomme ich es funktioniert?

Dank

InformationsquelleAutor Mimo | 2015-02-14
Schreibe einen Kommentar