Live data from Hacker News

The Day Python Embarassed Imperative Programming

the-27th-comrade.appspot.com

31–40 of 80 posts

Re: The Day Python Embarassed Imperative Programming

#31

In Python, every object is an example of a monad. It has two possible values: None and anything_else. Is no more true then, "It has two possible values: 'Hello, I am a sexy bear' and anything_else."

Poorly worded, but the point is that every reference in Python, like in Java, ALGOL 60 and countless other languages, may be of a certain type, or point to None. In Haskell, save for a caveat[1], this doesn't happen, and you represent nullability (failure, usually) with types like Maybe or Either, when you want to. Those happen to be monads, too, but you can use them without the monadic operators.

[1] The caveat is the bottom value, which represents something akin to an exception which wasn't handled, that your program is now in an undefined state and now will promptly crash if you use the 'bad' part.

Re: The Day Python Embarassed Imperative Programming

#32

I read the article and I still don't understand what monads are about. This happens every time. There must be something about the Haskell syntax (which has been ages since I used it in college--and I utterly failed to grasp monads then, too) it's very frustrating, I get the rest of functional programming. Apparently I forgot how to read Haskell.

Its not the syntax, its the concept that's hard. I read about 10 different monad tutorials, and it only made things worse. The only thing that made it click was writing code that used them. (Some monadic parser code.)

Seriously, reading monad explanations is like struggling in quicksand of abstraction. Only by making it concrete in working code did I make any progress.

If I had to pick the most tractable monad, I would try the Maybe monad, use it for map lookups in Haskell's Data.Map, since its something you would commonly do with a Python dictionary anyway.

Re: The Day Python Embarassed Imperative Programming

#34
It is embarrassing for google app engine to allow unusual spikes like that to bring a site down. What better PR strategy to let the sites up and running to show that no google property can ever be slashdotted/dugg/hackernewsed?

Google please fix this mess, elegantly.

Re: The Day Python Embarassed Imperative Programming

#35

Earlier quoted context omitted.

I'm just getting it now. Google for something called Typeclassopedia and read about Functors, and then Applicative functors. Those are much easier to understand right away, and they set the stage for monads. Applicative functors relate to functors in an obvious way (you could probably implement one in terms of the other). Monads relate to applicative functors in a less obvious way, to me anyway, but at least it's ana…

"Learn you a Haskell for great good" is probably the most approachable book on the subject you can read it online for free. People who are confused should definitely check it out.

Yes, it is by far the best way to learn what monadic really means. http://learnyouahaskell.com/chapters is the book, but if you already understand basic Haskell syntax, you can start at Chapter 11, Functors: http://learnyouahaskell.com/functors-applicative-functors-an...

Yes, it's a bit long, but it actually works, and, what's more, unlike the vast majority of monad tutorials written by someone who just sort of half figured out the concept half-an-hour ago (but they really didn't), it is also correct. This is one of the major root causes behind people's general inabilities to "understand monads after reading tons of tutorials", the tutorials are not only generally not very good but often wrong and mutually contradictory.

Re: The Day Python Embarassed Imperative Programming

#36

It is embarrassing for google app engine to allow unusual spikes like that to bring a site down. What better PR strategy to let the sites up and running to show that no google property can ever be slashdotted/dugg/hackernewsed? Google please fix this mess, elegantly.

How would I fix it you may ask? Well for app engine free riders like me, just allow one or two excessive spikes per month. That way if you have a blog nobody reads but is front-paged once in a blue moon, you won't go down in flames making app engine look bad.

Now those being on the spotlight more than twice please consider upgrading your account or adding a banner at the bottom of your site "indestructibly hosted on app engine" to continue free riding.

Re: The Day Python Embarassed Imperative Programming

#37
post #11
post #8

I don't get it. I see this; def pymon(f, v = None): if v: return f(v) and I just can't keep reading. Why would you do that? What reason would you have for not just calling f directly?

You wouldn't want to call f directly if it doesn't accept None . pymon is a function meaning f(v) if v else None .

wouldn't it be better to a) code f defensively in the first place, and b) not call f with invalid parameters?

Re: The Day Python Embarassed Imperative Programming

#38
post #11

Earlier quoted context omitted.

You wouldn't want to call f directly if it doesn't accept None . pymon is a function meaning f(v) if v else None .

wouldn't it be better to a) code f defensively in the first place, and b) not call f with invalid parameters?

It's a workaround for Python not being able to type-check, compared to Haskell.

Re: The Day Python Embarassed Imperative Programming

#39
post #14
post #3

"The Python programmer said he had downloaded BASIC, and was experimenting with it. “But what is this GOTO stuff?” Never. Never ever ask that. One negative effect of asking that question is the horror of finding out that you use GOTO more than BASIC programmers; but because they are everywhere in your life, you have developed a blind spot to them. (Hint: do you use if?) In fact, as I showed him, every control structu…

A nice analogy, but I would argue that as monads are at a higher level of abstraction than nullables it's more akin to "but what is this if stuff?" It is the f(v) if v else None which is analogous to GOTO, not the simpler and more direct v >>= f .

Followed by a misleading explanation that suggests turning ALL your gotos into ifs.

Re: The Day Python Embarassed Imperative Programming

#40

It is embarrassing for google app engine to allow unusual spikes like that to bring a site down. What better PR strategy to let the sites up and running to show that no google property can ever be slashdotted/dugg/hackernewsed? Google please fix this mess, elegantly.

Possibly the author is doing something inefficient that shouldn't happen in a mostly-static blog? In which case Google could provide a bit of load testing so that people know their site won't survive a social aggregator. Or offer some read-only version, idk.
Post reply on HN