Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Point-free programming style

Name: Anonymous 2009-01-04 19:30

How do I write the factorial function in point-free?

fact n = foldr1 (*) [1..n]

Which is faster
add1 = 1 +
or
add1 x = 1 + x
???

Name: Anonymous 2009-01-05 16:16

>>54 Good point.

>>53
The factorial is meant to be the same. It wouldn't be much use if a different function was tested, would it? I defined them separately because I didn't want to JS implementation to make assumptions about the function and them have those assumptions possibly broken when it's called in a different manner.

Anyway, as you spotted, I was using an incorrect version of the file. With the proper version below they perform the same (except on TraceMonkey, which you obviously aren't using anyway if you managed to get 567ms earlier). So your claim that using arguments/apply would be "way slower" is still false.

function loopAnon(n) {
  return function(f, args) {
    for(var i = 0; i <= n; ++i) {
      var res = f.apply(null, args);
    }
  }
}

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List