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

Hector Guilarte hectorg87 at gmail.com
Wed Apr 28 11:44:14 EDT 2010


Hey!

Keep passing the current char to your next call of the function (your next "iteration" as you said), that way you have the previos char in the current "iteration" and you can use it. The first time you call it make sure you call it with a dummy char that you know it will do what supposed to.

Greetings,

Hector Guilarte

Enviado desde mi dispositivo movil BlackBerry® de Digitel.

-----Original Message-----
From: Jean-Nicolas Jolivet <jeannicolascocoa at gmail.com>
Date: Wed, 28 Apr 2010 10:56:37 
To: <beginners at haskell.org>
Subject: [Haskell-beginners] Iterating through a list of char...

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
_______________________________________________
Beginners mailing list
Beginners at haskell.org
http://www.haskell.org/mailman/listinfo/beginners


More information about the Beginners mailing list