News for hackers. Stuff that matters.
Re:Curing Python's Neglect by nathanic on Friday May 29, 2009 @07:05PM (#633020)
I personally like how Haskell can combine the two. You can have:

  myFunc = do
    this
    that
    other
Or equivalently:

  myFunc = do { this; that; other; }
Re:Curing Python's Neglect by natrius on Friday May 29, 2009 @07:47PM (#633050)
How does the first form work out as an inline function argument? I'm not familiar with Haskell's syntax.
Re:Curing Python's Neglect by nathanic on Friday May 29, 2009 @08:07PM (#633068)
I think I misunderstood you before. I thought you were talking about putting multiple statements on a line.

But Haskell can pass around code blocks as well, with or without significant whitespace.

For example, I can define a function called 'forever' to run a sequence of actions forever like so:

  forever x = x >> forever x
Where 'x' is any sequence of actions. You can pronounce '>>' as "followed by". (These are monadic actions, actually, but nevermind that.)

I can invoke it like so:

  myFunc = forever (do {this; that; other})
or:

  myFunc = forever $ do
    this
    that
    other
The dollar sign is a function that lets you dispense with some parentheses. Think of it like an opening paren that closes at the end of the subexpression it's in.

If the block is a function rather than a sequence of actions, Haskell uses '\' as a lambda for introducing anonymous functions.

For example, the function 'map' takes a unary function and calls it with each value from a list. Below I'll call it with an anonymous function which returns double its argument:

  map (\x -> x * 2) [1,2,3]
This results in a new list [2,4,6].
Re:Curing Python's Neglect by shrughes on Friday May 29, 2009 @11:30PM (#633223)
Another good example:

    forM_ [1..9] $ \i -> do
      this i
      that
      other