4 ms·
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
by kingkilr 15y ago
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."
- indiecore 15y agoEverything in life is 50/50, either it happens or it doesn't. The statistics industry is just trying to pull the wool over our eyes. WAKE UP SHEEPLE.
- klodolph 15y agoWhy pull a quote out of context to nitpick it? The article goes on to explain how common it is to check if an object is None and act differently, which is what gives us the same monadic structure as the Maybe monad in Haskell.
- danieldk 15y agoExcept that 'Hello, I am a sexy bear' is generally not used to indicate failure in Python, while None often is. Edit: strange downvoting here :/. The parent has a point in the sense that None is just another object in Python. However, it's a singleton with a special meaning (by convention). Consequently, the parent used a false analogy.
- whateverer 15y agoPoorly 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.
- mikeash 15y agoNull is an interesting exception in languages with static typing such as Java. But there is no static typing in Python. Literally any variable can hold any value of any type. None is not nearly so special there, since you can also assign 3 to any variable, or the identity function, or a string containing the answer to the question of life, the universe, and everything. In languages like Java, null has special semantics that no other value has. In Python, there's nothing particularly special about None, it's simply used as a convenient sentinel by convention. I could easily write Python code that returns the literal string "This value is empty" as the sentinel instead, something that doesn't apply to languages like Java.
- whateverer 15y agoYes, actually, you are right. It's all the same in Python because the references can always point to any value, and None is just a value of the NoneType. And due to Python's runtime types, it wouldn't matter either way, because even if None only existed within the context of a Maybe type, you could still just apply any operation on it and have crash at the first method call on it.
- SoftwareMaven 15y agoThat's not completely accurate. None is still special in Python because it's the value chosen by the interpreter to represent an expression that doesn't explicitly return a value. It is true that None is implemented like any other object (whther the value of 5 or an instance of my own class), but it still maintains special semantics.
- icebraining 15y agoevery reference in Python, like in Java, ALGOL 60 and countless other languages, may be of a certain type, or point to None. Well, in Python every reference may be of any type. None is just another object, there's nothing particularly special about it.