I'm currently trying to learn folding.
But instead of using predefined functions I want to use my own.
So I want to double all vowels in a String.
doubleVowels :: String -> String
My attempt is (yet just for 'a', as I'm try solve it for one letter first and will expand and optimize it, once it runs):
doubleVowels :: String -> String
doubleVowels a = foldl (\eachChar -> if eachChar == 'a' then (a ++ "aa") else a) "" a
Trying to run he code I'm getting the following 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.