Notes on Haskell: What's Wrong with the For Loop
51–59 of 59 posts
Re: Notes on Haskell: What's Wrong with the For Loop
#52You can execute loop in your head just by reading it line by line. Token by token. With other solutions you need to know other things to determine what goes inside and believe it is actually what you want it to be. Loops ar flat, explicit and versatile. I think that is the reason behind their popularity.
Re: Notes on Haskell: What's Wrong with the For Loop
#53"But it does highlight the key failing of for loops: they conflate three separate kinds of operations -- filtering, reduction and transformation." There's actually four kinds of operations: filtering, reduction, transformation, and good Lord man what the hell are you doing with the loop index? did it just go negative? It did! Why? And it still works‽ , which is actually quite hard to simulate with functional programm…
I can top that mine went up to 17 and then jumped to 200 for no obvious reason(some sort of memory bug where memory in a different part of the program overlapped with the loop variable).
Re: Notes on Haskell: What's Wrong with the For Loop
#54Earlier quoted context omitted.
Yes, this has been one of my pet peeves for a while too. Everybody: a closure, as the parent says, is an implementation construct. It is not something you can find in your source code. The syntactic construct -- the thing you write in your code -- is called a lambda expression . Not a "lambda function", and not a "closure"! Lambda expressions are to closures as `new' expressions are to instances: a lambda expression…
> Instances and closures are closely related: an instance is a piece of state with several operations that can be invoked on it, while a closure is a piece of state with one operation that can be invoked on it. I would go further, and say that they're equivalent—that "one operation" can be a dispatch function: def make_object x = 5 lambda do |m| case m when 'increment' x += 1 when 'decrement' x -= 1 when 'get' x end…
Re: Notes on Haskell: What's Wrong with the For Loop
#55You can execute loop in your head just by reading it line by line. Token by token. With other solutions you need to know other things to determine what goes inside and believe it is actually what you want it to be. Loops ar flat, explicit and versatile. I think that is the reason behind their popularity.
If you're familiar with foldr or its ilk you can execute them in your head token by token too, to the same extent you can in a for loop. In the case of a for loop you have to be familiar with the syntax and semantics of "for" in your language so you know that "for(i = 0; i<n; i++)" is different from "for(i = 0; i++; i < n)" and likewise you have to be familiar with the syntax and semantics of any functional construct…
Re: Notes on Haskell: What's Wrong with the For Loop
#56Earlier quoted context omitted.
> Instances and closures are closely related: an instance is a piece of state with several operations that can be invoked on it, while a closure is a piece of state with one operation that can be invoked on it. I would go further, and say that they're equivalent—that "one operation" can be a dispatch function: def make_object x = 5 lambda do |m| case m when 'increment' x += 1 when 'decrement' x -= 1 when 'get' x end…
In fact, in SICP, they build their object system in this way, if my memory serves me correctly.
[1] http://codermonk.blogspot.com/2007/01/venerable-master-qc-na...
Re: Notes on Haskell: What's Wrong with the For Loop
#57Earlier quoted context omitted.
If you're familiar with foldr or its ilk you can execute them in your head token by token too, to the same extent you can in a for loop. In the case of a for loop you have to be familiar with the syntax and semantics of "for" in your language so you know that "for(i = 0; i<n; i++)" is different from "for(i = 0; i++; i < n)" and likewise you have to be familiar with the syntax and semantics of any functional construct…
To understand loop you just need to know in which order to execute its parts. And you see how it reduces, maps an filters your data. You don't need to keep stack in your head. To understand how functional constructs work you have to know a lot more because they are specialised and it's not that easy to track what they exactly do because of recursion. You have to know them and trust them. With loop all internal logic…
So you can execute a loop C-token by C-token and you can execute a fold Haskel-token by Haskel-token, but both are abstractions high above whats happening at the machine level and I don't see why we should prefer one over the other.
Re: Notes on Haskell: What's Wrong with the For Loop
#58Colour me stupid, but in the article it gives this code as having some horrible hard to find bug: String s = ""; for (int i = 0; i Now, as soon as I looked at that I immediately thought "well, they're not putting anything in between the params when they concatenate them", e.g. I would expect to see: s += array[i] + "\t"; (or a comma or newline instead of a tab) My next thought was "what happens if there are no args?"…
"What am I missing?" What a noob! for (int i = 0; i If args.length is zero, the body of the loop won't run, since 0 < 0 is false. Duh.
Re: Notes on Haskell: What's Wrong with the For Loop
#59Earlier quoted context omitted.
"What am I missing?" What a noob! for (int i = 0; i If args.length is zero, the body of the loop won't run, since 0 < 0 is false. Duh.
Parent didn't need the downmods - it's the same poster replying to himself with "what a noob". I was about to post this same answer till I saw this at the bottom of the replies.
It's okay. I continue to be baffled and amazed at what gets voted up and what gets voted down, usually it balances out, so if something gets unexpectedly voted down, something else will get unexpectedly voted up.