[Haskell-beginners] string instead of char

Robert Ziemba rziemba at gmail.com
Sun Oct 4 14:55:05 EDT 2009


You can also do something like this instead of the case statement (this is
using GHCI).
Prelude> let exclude = ['a', 'e', 'i', 'o', 'u']
Prelude> let f excl letter | letter `elem` excl = 'x' | otherwise = letter
Prelude> map (f exclude) "hello"
"hxllx"

Rob Ziemba

On Sun, Oct 4, 2009 at 9:10 AM, Colin Paul Adams
<colin at colina.demon.co.uk>wrote:

> >>>>> "John" == John Moore <john.moore54 at gmail.com> writes:
>
>    John> Hi, I am now writing a function that replaces vowels with
>    John> the letter x.  eg.put in a string "help" and out comes hxlp.
>    John> I tried this:
>
>    John> f x = case x of
>
>    John>       {'a' -> 'x';'e' -> 'x';'i' -> 'x';'o' -> 'x';'u' ->
>    John> 'x';_ -> x}
>
>    John> but this wont work on strings, only on the individual
>    John> letters. Any direction would be very welcome.
>
> You need to call
>
> map f "whatever"
>
> where f is your function for replacing a character (as above).
> --
> Colin Adams
> Preston Lancashire
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://www.haskell.org/mailman/listinfo/beginners
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/beginners/attachments/20091004/68b6b7a0/attachment-0001.html


More information about the Beginners mailing list