Re: [Haskell-cafe] Repeated function application

2008-02-22 Thread Dan Weston
Actually, the second argument is already strict, and the ! doesn't make it any stricter (and is therefore gratuitous): when you evaluate the conditional (n == 0), n is evaluated. Dan Thomas Hartman wrote: On second thought... never mind. The only thing of (somewhat marginal) interest that my

Re: [Haskell-cafe] Repeated function application

2008-02-22 Thread Thomas Hartman
On second thought... never mind. The only thing of (somewhat marginal) interest that my latest comment adds is that the second argument doesn't need to be strict. Otherwise my code is exactly identical to Dan's. 2008/2/22, Thomas Hartman <[EMAIL PROTECTED]>: > This was easier for me to understan

Fwd: [Haskell-cafe] Repeated function application

2008-02-22 Thread Thomas Hartman
This was easier for me to understand when written so, with the start value explicit times3 :: (a -> a) -> Int -> (a -> a) times3 f n !start | n == 0 = start | otherwise = times3 f (n-1) (f start) -- no stack overflow :) tTimes3 = times3 (+1) 100 0 Here, only the

Re: [Haskell-cafe] Repeated function application

2008-02-21 Thread Dan Weston
Ben Butler-Cole wrote: Hello I was surprised to be unable to find anything like this in the standard libraries: times :: (a -> a) -> Int -> (a -> a) times f 0 = id times f n = f . (times f (n-1)) Am I missing something more general which would allow me to repeatedly apply a function to an in

Re: [Haskell-cafe] Repeated function application

2008-02-21 Thread Wolfgang Jeltsch
Am Donnerstag, 21. Februar 2008 16:58 schrieb Ben Butler-Cole: > Hello > > I was surprised to be unable to find anything like this in the standard > libraries: > > times :: (a -> a) -> Int -> (a -> a) > times f 0 = id > times f n = f . (times f (n-1)) times f n = (!! n) . iterate f > […] Best wi

Re: [Haskell-cafe] Repeated function application

2008-02-21 Thread jerzy . karczmarczuk
Ben Butler-Cole writes: times :: (a -> a) -> Int -> (a -> a) times f 0 = id times f n = f . (times f (n-1)) Am I missing something more general ...I can't help feeling that there must be a way to get rid of the explicit recursion. How would you implement times? Anything against (apart

[Haskell-cafe] Repeated function application

2008-02-21 Thread Ben Butler-Cole
Hello I was surprised to be unable to find anything like this in the standard libraries: times :: (a -> a) -> Int -> (a -> a) times f 0 = id times f n = f . (times f (n-1)) Am I missing something more general which would allow me to repeatedly apply a function to an input? Or is this not usefu