Apply a function multiple times in Haskell

haskell, higher-order-functions

Solution

I always did something like `iterate f x !! n`.

Problem

Learn You a Haskell For Great Good (section "Higher Order Functions", subsection "Some higher-orderism is in order") describes an example function `applyTwice` that calls a function on an argument twice: ``` applyTwice :: (a -> a) -> a -> a applyTwice f x = f (f x) ``` But i need a function that applies some function over some argument an arbitrary amount of times. For example `applyN 3 f x` would be equivalent to `f $ f $ f x`. How would i write a function of repeated application in Haskell? Please post any possible solutions, using recursion, higher-order functions or anything else.

Original source

Related problems