from Hacker News

Exotic List Monads

by curryhoward on 1/6/21, 8:10 AM with 25 comments

  • by nemo1618 on 1/8/21, 12:47 AM

    > The usual list monad is only one of infinitely many ways to turn the List functor into a monad.

    So simple, and yet this is a point that I think is rarely made clear enough in "monad explainers." For instance, they almost always talk about "the Maybe monad" -- but this is conflating two things: the Maybe data type, and the Monad instance defined on that type. Propagating "Nothing" is not inherent to the Maybe data type, it's just a convenient behavior to have.

    Talking about "the List monad" is even more confusing for a newcomer. When they hear "the List monad implements a kind of nondeterminism," it sounds like nondeterminism is a property inherent to lists themselves -- but of course it is nothing of the sort. All Monad instances are, in a sense, arbitrary.

  • by lmm on 1/8/21, 2:14 AM

    > In each case return is singleton (it is not known if there exists a monad on lists with a different return).

    The "diagonal" monad join [[a, b, c, ...], [1, 2, 3, ...], [x, y, z, ...], ...] = [a, 2, z, ...] has return a = [a, a, a, ...], though I guess it's hard to define it in a way that's well-behaved for finite lists, so you might not consider it "a monad on lists".

  • by jitl on 1/7/21, 10:54 PM

    No comments, because no one understand these (At least, I don't).
  • by ashton314 on 1/8/21, 6:44 AM

    I appreciate comment threads like this because it shows me I have a lot to learn. HN is a great place to encounter people smarter than you.
  • by zgotsch on 1/7/21, 11:11 PM

    I don’t see how this has broad appeal, but at least the Mazewalk interpretation is cute.