Notes on Haskell: What's Wrong with the For Loop
notes-on-haskell.blogspot.com
Notes on Haskell: What's Wrong with the For Loop
1–10 of 59 posts
Re: Notes on Haskell: What's Wrong with the For Loop
#2I wonder why there aren't more people advocating the use of these functions in Python programs instead of for loops.
Re: Notes on Haskell: What's Wrong with the For Loop
#3A simple example showing the usefulness of inner functions might have been more pertinent to the term closure IMO.
Re: Notes on Haskell: What's Wrong with the For Loop
#4Heh, all of these points could easily be applied to Python as well. All the concepts are there in addition to the for loop. It's nice how you can do a lot of functional programming in Python with these simple tools (map, filter and reduce (Haskell's foldl). I wonder why there aren't more people advocating the use of these functions in Python programs instead of for loops.
I'm usually only reading and not writing python but I think list comprehensions are more idiomatic. Based on some comments I've seen here I also kind of get the impression comprhensions are abused.
Re: Notes on Haskell: What's Wrong with the For Loop
#5Heh, all of these points could easily be applied to Python as well. All the concepts are there in addition to the for loop. It's nice how you can do a lot of functional programming in Python with these simple tools (map, filter and reduce (Haskell's foldl). I wonder why there aren't more people advocating the use of these functions in Python programs instead of for loops.
Java's younger cousin C# also has this with Select, Where and Aggregate. But sometimes the foreach and even the for loop actually makes more sense, in particular when dealing with very imperative algorithms or are not acting over a (full) sequence at all. I'm usually only reading and not writing python but I think list comprehensions are more idiomatic. Based on some comments I've seen here I also kind of get the imp…
Re: Notes on Haskell: What's Wrong with the For Loop
#6Earlier quoted context omitted.
Java's younger cousin C# also has this with Select, Where and Aggregate. But sometimes the foreach and even the for loop actually makes more sense, in particular when dealing with very imperative algorithms or are not acting over a (full) sequence at all. I'm usually only reading and not writing python but I think list comprehensions are more idiomatic. Based on some comments I've seen here I also kind of get the imp…
Well, if you don't want to work with the whole sequence, you can filter it. But yeah, in those cases and some others, the for loop may be more idiomatic and better performing.
Re: Notes on Haskell: What's Wrong with the For Loop
#7Heh, all of these points could easily be applied to Python as well. All the concepts are there in addition to the for loop. It's nice how you can do a lot of functional programming in Python with these simple tools (map, filter and reduce (Haskell's foldl). I wonder why there aren't more people advocating the use of these functions in Python programs instead of for loops.
For-loops are still suitable for actions (which mutate state or for some other reason need to be evaluated in order) - you see this in Haskell, too, though, with Control.Monad's forM_ and the like.
Re: Notes on Haskell: What's Wrong with the For Loop
#8Heh, all of these points could easily be applied to Python as well. All the concepts are there in addition to the for loop. It's nice how you can do a lot of functional programming in Python with these simple tools (map, filter and reduce (Haskell's foldl). I wonder why there aren't more people advocating the use of these functions in Python programs instead of for loops.
(Nitpicking forever!)
Re: Notes on Haskell: What's Wrong with the For Loop
#9Earlier quoted context omitted.
Well, if you don't want to work with the whole sequence, you can filter it. But yeah, in those cases and some others, the for loop may be more idiomatic and better performing.
Yes I'm talking about being able to stop early for one example. Or if the thing you are dealing with is not actually a sequence for another.
The latter is a different thing..
Re: Notes on Haskell: What's Wrong with the For Loop
#10Earlier quoted context omitted.
Yes I'm talking about being able to stop early for one example. Or if the thing you are dealing with is not actually a sequence for another.
The former can probably be solved for lots of cases by TakeWhile(), which evaluates before consuming more elements and could be used to replace "abort the loop" patterns. The latter is a different thing.. 1: http://msdn.microsoft.com/en-us/library/bb534804.aspx