[Haskell-beginners] Re: Iterating through a list of char...

jean verdier verdier.jean at gmail.com
Thu Apr 29 09:52:40 EDT 2010


I may have missed it in this thread, but if not, why didn't anyone
suggest:

trans []         = []
trans [x]        = [x]
trans ('a':_:xs) = 'a' : 'A' : trans xs 
trans     (x:xs) =        x  : trans xs




On Thu, 2010-04-29 at 05:46 -0700, Hein Hundal wrote:
> Jean-Nicolas,
> 
>    Here is a variation on Corentin's solution:
> 
> -- This function replaces every character that 
> -- follows an 'a' with 'A'
> 
> repA :: String -> String
> 
> repA s = zipWith f (' ':s) s where
>    f 'a' y = 'A'
>    f  x  y =  y 
> 
> Cheers,
> Hein
> 
> 
> > From: Jean-Nicolas Jolivet <jeannicolascocoa at gmail.com>
> >
> > I'm trying to iterate through each character of a string
> > (that part I
> > can do!) however, I need to apply a transformation to each
> > character...based on the previous character in the string!
> > This is the part I have no clue how to do!
> > [snip]
> > while i < my_string length:
> >     if my_string[i-1] == some_char:
> >         do something with
> > my_string[i]
> >     else
> >         do something else
> > with my_string[i]
> 
> 
> 
>       
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://www.haskell.org/mailman/listinfo/beginners




More information about the Beginners mailing list