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

Jean-Nicolas Jolivet jeannicolascocoa at gmail.com
Wed Apr 28 10:56:37 EDT 2010


Hi there!

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!

I'm totally new to Haskell so I'm pretty sure I'm missing something
obvious... I tried with list comprehensions...map... etc... but I
can't figure out how I can access the previous character in my string
in each "iteration".... to use simple pseudo code, what i need to do
is:

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]

I'm using imperative programming here obviously since it's what I am
familiar with...but any help as to how I could "translate" this to
functional programming would be really appreciated!


Jean-Nicolas Jolivet


More information about the Beginners mailing list