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
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
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
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
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
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
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