ฉันกำลังพยายามที่จะเรียนส่วนพับเก็บได้.
แต่แทนที่จะใช้ค่าที่นิยามไว้แล้วฟังก์ชันที่ฉันต้องการที่จะใช้ของฉันเอง
ดังนั้นฉันต้องการให้สองเท่าทั้ง vowels ในข้อความ
doubleVowels :: String -> String
ของฉันคือความพยายาม(ยังแค่สำหรับ"a"อย่างที่ฉันพยายามแก้ไขมันสำหรับหนึ่งจดหมายแรกและจะขยายและ the result will be artificially smoothed to hide jpeg artefacts มันเมื่อมันวิ่ง):
doubleVowels :: String -> String
doubleVowels a = foldl (\eachChar -> if eachChar == 'a' then (a ++ "aa") else a) "" a
พยายามที่จะวิ่งหนีเขารหัสฉันกำลังต่อไปนี้ erorr:
Experimenting.hs:8:78: error:
* Couldn't match type `[Char]' with `Char -> Char'
Expected type: Char -> Char
Actual type: String
* In the expression: a
In the expression: if eachChar == 'a' then (a ++ "aa") else a
In the first argument of `foldl', namely
`(\ eachChar -> if eachChar == 'a' then (a ++ "aa") else a)'
|
8 | doubleVowels a = foldl (\eachChar -> if eachChar == 'a' then (a ++ "aa") else a) "" a
| ^
Experimenting.hs:8:81: error:
* Couldn't match expected type `Char' with actual type `[Char]'
* In the second argument of `foldl', namely `""'
In the expression:
foldl
(\ eachChar -> if eachChar == 'a' then (a ++ "aa") else a) "" a
In an equation for `doubleVowels':
doubleVowels
= foldl
(\ eachChar -> if eachChar == 'a' then (a ++ "aa") else a) "" a
|
8 | doubleVowels a = foldl (\eachChar -> if eachChar == 'a' then (a ++ "aa") else a) "" a
| ^^
Failed, no modules loaded.