←back to thread

A list is a monad

(alexyorke.github.io)
153 points polygot | 5 comments | | HN request time: 0.001s | source
Show context
nemo1618 ◴[] No.44447106[source]
I think this adds more confusion than it removes.

A list is not a monad. A list is a data structure; a monad is more like a "trait" or "interface." So you can define a List type that "implements" the monad interface, but this is not an inherent property of lists themselves. That's the sense in which a list "is a" monad: the OOP sense.

Haskell's List monad provides a model for nondeterminism. But that certainly isn't the only way List could satisfy the monad interface! It was a deliberate choice -- a good choice, possibly the best choice, but a choice nonetheless.

replies(4): >>44447152 #>>44447222 #>>44448276 #>>44451386 #
Jaxan ◴[] No.44447222[source]
Isn’t it the case that for a given functor (on Set) there can only be at most one Monad structure?
replies(1): >>44447514 #
1. whateveracct ◴[] No.44447514[source]
Nope. It's that there's only one lawful Functor instance. But Applicatives and Monads can be multiple - lists are the classic example (zip vs cross-product)
replies(3): >>44447597 #>>44447622 #>>44447640 #
2. Jaxan ◴[] No.44447597[source]
Ah right. Didn’t remember it correctly.
3. ◴[] No.44447622[source]
4. ryandv ◴[] No.44447640[source]
The cross-product is not to be confused with the Cartesian product, which is related to the (in this case unfortunately named) "cross join" in SQL. Cross products operate in ℝ³, while Cartesian products are just defined over sets. The standard List monad instance uses the latter.
replies(1): >>44448942 #
5. whateveracct ◴[] No.44448942[source]
ah yes my bad! good callout