
How to read Haskell like Python - xtacy
http://blog.ezyang.com/2011/11/how-to-read-haskell
======
antipax
To be fair, monadic code does not necessarily have side effects. It's just a
useful way of thinking about computational steps. `Maybe` is a monad that is
completely pure and has no side effects:
[http://www.haskell.org/ghc/docs/latest/html/libraries/base/s...](http://www.haskell.org/ghc/docs/latest/html/libraries/base/src/Data-
Maybe.html#line-76)

I understand that this article is geared towards beginners, so this is
probably just a simplification on the author's part. Other than that it's a
great article.

~~~
joeyh
The problem with the simplification is that you really need to understand
which monad code is using to read the code. foo >>= bar >>= baz has very
different behaviors in the IO monad (it's like a shell pipe foo | bar | baz)
and the Maybe monad (it's like a short-circuiting foo && bar && baz).

~~~
ezyang
Not really... you're perfectly capable of reading Python code:

    
    
      x = foo()
      y = bar(x)
      baz(y)
    

Knowing that any of these functions could throw an exception. How is it any
different, from the reader's perspective? (Yes, it's /very/ different from an
implementation perspective, but that's not what we're dealing with here...)

------
yobbobandana
I've tried to learn Haskell a couple times, and I keep running into the basic
problem of not being able to search for info on terms like ">>=". If you don't
know what it means, how do you find out? I certainly never knew until reading
in this article that they were called "fish" operators. I previously tried to
work through 3 or 4 different Haskell tutorials, and still didn't know this.

This article seems very helpful for simply enabling someone with Python
experience to learn Haskell.

~~~
tikhonj
They aren't actually called "fish" operators, as far as I know. ">>=" is
pronounced "bind"; all the other ones are related. I didn't have this problem
when learning Haskell because I just started by reading "Learn You a Haskell
for Great Good"--which is a great book, coincidentally--and never had to
google operators.

~~~
ezyang
OK OK, "Bind and fish" operators. :-)

~~~
tikhonj
I actually rather like the name "fish operator". I just wanted to point out
that Googling for that phrase wouldn't really work.

------
eru
A set of useful lies.

Some of my co-workers were interested in learning to read Haskell, not so much
in writing it. Let's see whether they like it.

------
samg_
For me, one of the biggest obstacles to understanding lots of Haskell code is
opaque infix operators.

~~~
Peaker
There aren't that many of them in the Prelude and common libraries.

Besides the standard arithmetic ones, only ones I can think of are the "fish"
operators, composition dot, and a few arrows.

Did you try to learn what they mean, or did you give up earlier than that?

~~~
lubutu
To be precise: cons (:), bind (>>=), 'constant bind' (>>), 'flipped bind'
(=<<), compose (.), apply ($), strict apply ($!), append (++), and subscript
(!!).

~~~
joeyh
I had never seen $! before, of course it's obvious what it does if you know !
and $. There are patterns like this throughout the operators.

There are also the applicatives <$> <*> <$ etc.

------
mvzink
_> But Haskell programmers are allergic to extra variables._

Point-free style, best style. <http://news.ycombinator.com/item?id=3233870>

------
kemiller
I think the "dabbling" phase of learning a language is important, and this is
the best intro for Haskell dabblers I've ever seen. Nice work, author.

------
switz
Is it weird that I know haskell and not python? I think so.

------
rfugger
Whoa, as a python guy, this makes me not want to learn Haskell at all. The
syntax seems as bad a Perl.

~~~
MostAwesomeDude
Nah, it's no biggie. What really is rough is the adherence to static types;
it's very harsh and can really slow down a person hoping to build things.

And of course, if you're like me, then you don't want to go into a language
where there's no Twisted equivalent.

~~~
ezyang
I can't tell if you're trolling. GHC Haskell has first class pre-emptive
concurrency support. You don't need Twisted because we give that all to you,
out-of-the-box, without needing to do anything fancy.

~~~
jrockway
I think he is complaining that he can write code in a natural form and then
GHC's runtime makes the necessary calls to the event loop to make things
happen as declared. This is annoying because all the hours you spent trying to
work around Python turned out to be a big waste of time. Or something.

