Exotic List Monads
21–27 of 27 posts
Re: Exotic List Monads
#22> 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…
At the language level, FP seperates data from behavior. However, in practice, even functional programmers still tend to couple data and behavior. For instance, not much would change about programming in Haskell if List was defined as an abstract type, so users couldn't see its constructor or interact with it in any way except through its functions. In OOP languages, this is unambiguous because the function/interface…
Re: Exotic List Monads
#23Re: Exotic List Monads
#24Earlier quoted context omitted.
> Propagating "Nothing" is not inherent to the Maybe data type, it's just a convenient behavior to have. nitpick about this particular example: is there another lawful implementation of Monad for Maybe? i can't think of any, apart from the trivial pure _ = Nothing _ >>= _ = Nothing (eyeballing the lawfulness, but it'll all be `Nothing` so all the equalities should hold, trivially :D)
The trivial implementation isn't law abiding. This law doesn't hold (written in Kleisli form for simplicity) pure >=> f == f (left identity) There are no other monads for Maybe. First, any definition of pure must be Just as Nothing doesn't work because of left identity and parametricity prevents any other funny business. Now, by law we know pure a >>= f == f a Thus, we must define Just a >>= f = f a So the only varia…
Re: Exotic List Monads
#25Earlier quoted context omitted.
Exactly, and the right identity is also violated: m >>= pure ≡ m
ahh right! serves me right, i should've spent more than 10 secs checking
I’m sure most real-world Haskell programs are “incorrect” in some way.