[Haskell-beginners] Repeat function application x times?

Magnus Therning magnus at therning.org
Sat Jul 23 08:26:05 CEST 2011


On Fri, Jul 22, 2011 at 10:11:39PM -0800, Christopher Howard wrote:
> Is there a convenient stock function in prelude/base that applies a
> function to a single value x number of times and returns the result?
> (I.e., does not return a list, but the final value.) Something like
> 
> applyN :: Integral b => (a -> a) -> b -> a -> a
> 
> Honestly I looked through the base hierarchy and at hoogle but I am
> missing it.

I'm not sure there is one, but it's rather simple to build one out of
`iterate` and `!!`.

/M

-- 
Magnus Therning                      OpenPGP: 0xAB4DFBA4 
email: magnus at therning.org   jabber: magnus at therning.org
twitter: magthe               http://therning.org/magnus

Most software today is very much like an Egyptian pyramid with
millions of bricks piled on top of each other, with no structural
integrity, but just done by brute force and thousands of slaves.
     -- Alan Kay
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: not available
URL: <http://www.haskell.org/pipermail/beginners/attachments/20110723/c5dec657/attachment.pgp>


More information about the Beginners mailing list