[Haskell-cafe] general

Jed Brown jed at 59A2.org
Sat Dec 8 15:27:08 EST 2007


On  8 Dec 2007, ryanbloor at hotmail.com wrote:

> Function A is a function that passes its input into B
> Function B is a function that does something once. 
>
> How do I make it so function A is done multiple times without adding a
> third function?

By this, do you mean that you have functions f, g

f :: a -> a
g :: a -> b

and you want

b . f . f . f . ... . f

where there are n applications of f?  If so, then

g . (!! n) . iterate f

will do the trick.  Alternatively, you can produce the infinite list, as
in:

map (^2) . iterate succ $ 0      -- [0,1,4,9,16,25,36,49,64,81 ...

Jed
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 196 bytes
Desc: not available
Url : http://www.haskell.org/pipermail/haskell-cafe/attachments/20071208/16abff59/attachment.bin


More information about the Haskell-Cafe mailing list