r/programming • • Dec 14 '19

Kleisli composition and other fishy operators

https://functional.christmas/2019/14
42 Upvotes

12 comments sorted by

7

u/Solonarv Dec 14 '19

While the footnote "monads don't compose" is true in general - if you pick two arbitrary monads, their composition is not always a monad - ctx -> in particular does compose with every other monad: If m is a monad, then e -> m _ is also a monad.

1

u/devraj7 Dec 14 '19

This is an important point.

Monads are often sold as the ultimate tool for composition and a lot of people feel very lied to when they realize that monads do not, actually, compose, and require monad transformers to do so.

-2

u/stronghup Dec 15 '19

Good point. Similarly, map() does compose but only when the output of one map() -call is such that the function-argument of next map()-call can handle that previous output.

3

u/Ewcrsf Dec 15 '19

Isn’t that just the definition of compositionality? Of course arbitrary things can’t be composed.

2

u/vegetablestew Dec 14 '19

What language are they using? Looks like Haskell but then angle bracket generics comes in.

4

u/therealgaxbo Dec 14 '19

He mentions F# later in the article.

2

u/bobappleyard Dec 14 '19

That might sound and indeed be confusing, but if you don't think too much about it, it kind of makes sense.

Wat

The reason we are using the bind operator here instead of the Kleisli fishbone operator,

Wat!?!

1

u/Iwan_Zotow Dec 15 '19

I would recommend short and simple book

https://gumroad.com/l/lcbk02

-12

u/memgrind Dec 14 '19

I read it as "here's how to save 1 keystroke, but cause a thousand head-scratches and 100 bugs, while ensuring your job security, while you look smug as no-one else understands it fully at a glance".

10

u/simendsjo Dec 14 '19

I love how your post doesn't refer to a context, and can apply to literally anything :) Everything is head-scratching until you understand it.

0

u/memgrind Dec 14 '19

The lines around ">>= Result.bind".