News for hackers. Stuff that matters.
Re:Do I really want to be using a language where memoize is ... by silentbicycle on Tuesday July 20, 2010 @11:30PM (#1534256)
I've seen people get exasperated trying to implement "if" in Prolog, too. The whole language is already an 'if' / pattern matching engine!

("How do you implement lazy evaluation in Haskell? No, like, in an application...")

Re:Do I really want to be using a language where memoize is ... by jrockway on Wednesday July 21, 2010 @01:59AM (#1534486)
Yeah, lazy evaluation can be surprising (in a good way). Once you get in the mindset of thinking "this is going to be hard", you start programming Haskell like you would C, and while it works, you feel stupid when you realize you just rewrote the Haskell compiler. Poorly.

(Personally, I have done this a number of times. I remember writing some dependency evaluation system, with a central data structure that looked something like:

   data Dependency a e = Thunk (e -> a) | Resolved a
with a bunch of code to turn a set of Thunks into Resolved when necessary.

But of course, Haskell always does this anyway!)

I was also surprised when I was on Windows and needed the "head" utility to look at the first line of a file, but didn't have it installed. Since I had a ghci session going, I just wrote:

   readFile "foo.csv" >>= putStrLn . unlines . take 10 . lines
Half-expecting it to error out because the file didn't fit into memory. Nope! Problem solved!

(And yes, I know unsafeInterleaveIO is evil.)