News for hackers. Stuff that matters.
Re:Ask HN: How to compose two mapping functions into a third? by nostrademons on Wednesday December 10, 2008 @08:15PM (#393754)
What you want is basically the compiler optimization called deforestation:

http://en.wikipedia.org/wiki/Deforestation_(computer_science)

It's only valid in a pure language, and in a strict language, it has the embarassing side-effect that it can sometimes make non-terminating programs terminate.

Re:Ask HN: How to compose two mapping functions into a third? by silentbicycle on Wednesday December 10, 2008 @10:48PM (#393911)
Just a note: you need to quote the parens in the link like so:

http://en.wikipedia.org/wiki/Deforestation_%28computer_scien...

And no, I don't know why this isn't mentioned in the FAQ or (better yet) the formatting options...

Re:Ask HN: How to compose two mapping functions into a third? by flashgordon on Thursday December 11, 2008 @12:18AM (#393992)
actually thanks guys for the great link... going deeper found this paper by Walder (one of the big gurus behind monads).. certainly a great read... was wondering why non-terminating progs would terminate till I read this paper (though thinking about it common sense would explain why)...

http://homepages.inf.ed.ac.uk/wadler/papers/deforest/defores...

Re:Ask HN: How to compose two mapping functions into a third? by gruseom on Thursday December 11, 2008 @01:42AM (#394050)
Thank you. This is interesting and I will have to make time to read Wadler's paper. This part of the program I'm working on is sort of compiler-like, so maybe a technique like that would work. (More likely, though, I'll end up sticking with the less elegant solution I already have, which involves defining two sets of functions rather than just the mapping ones.)