[Haskell-beginners] string instead of char

Joe Van Dyk joe at fixieconsulting.com
Mon Oct 5 14:24:43 EDT 2009


How about instead:

devowelize input | elem input "abcde" = 'x'
devowelize input = input

Not sure if pattern matching is appropriate here.

On Sun, Oct 4, 2009 at 12:14 PM, Michael Snoyman <michael at snoyman.com> wrote:
> Or instead of ['a', 'e', 'i', 'o', 'u'] use "aeiou". However, I think the
> case statement, while my verbose, is also clearer. But that's purely a style
> choice.
>
> Michael
>
> On Sun, Oct 4, 2009 at 8:55 PM, Robert Ziemba <rziemba at gmail.com> wrote:
>>
>> 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
>>
>>
>> _______________________________________________
>> Beginners mailing list
>> Beginners at haskell.org
>> http://www.haskell.org/mailman/listinfo/beginners
>>
>
>
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://www.haskell.org/mailman/listinfo/beginners
>
>



-- 
Joe Van Dyk
http://fixieconsulting.com


More information about the Beginners mailing list