Haskell uses a combination of different ways to 'sort of' loop over data, e.g. list.
The two important things helping this is:
- Ease of declaring a function and passing it around similar to what we do to a variable in oops languages
- Extensive pattern matching
So for example I declare a function in haskell to return 2 if input is 3 else return input.
return2 x = if x == 3 then 2 else x
Now we want to apply this function to every element of the list. So we will use pattern matching.
apply (x:xs) = return2 x : apply xs
apply [] = []
Here the pattern x:xs will break the list and take the first element in x while xs will have the remainder of the list. Inside the function you can see we have applied it recursively.
I have not checked the above code in IDE so it might have syntax errors, also there are other things you will want to validate (end of list, in above code the function would cause exception).
The above pattern is quite common, so there is another function in the core libraries that can do this, and is called map. So you could do:
map return2 [your list]
As I said, in haskell there are many ways to essentially loop over things, but at the base they break down to applying the function to individual items in the data structure. There are many haskell functions built on top of it like map, fold, etc.
I would suggest you use one of the several resources online to get more familiar with Haskell constructs. One that I liked and was easy to follow is Learn you a Haskell
How to think about loopsin Real World Haskell Chapter 4. Functional programming