How to run a for loop in Haskell

There’s no such a thing as a for loop in Haskell.

To apply a function to each element in a list, you can either use map or a list comprehension. Since you already have a list comprehension (which currently does not do anything), let’s just use that:

mainfun xs = [helpfun 2 x | x <- xs]

The alternative using map would be:

mainfun xs = map (helpfun 2) xs

Leave a Comment