There is another thing to mention. Even though in Haskell, you don't have loops, that doesn't necessarily mean you'd always write something recursively. I'm not a Haskell programmer, but I do work in functional languages and your particular example is really just naturally expressed using
map
(in fact, your list comprehension is pretty much Python's equivalent of calling map
in other languages. Well, it would be if you used the step
argument to range
instead of filtering in the even values). Whether that is done iteratively or recursively likely isn't your concern. Your example implemented in Clojure for example would look likeuser=> (range 0 10 2) (0 2 4 6 8) user=> (defn double-it [x] (* 2 x)) #'user/double-it user=> (map double-it (range 0 10 2)) (0 4 8 12 16)