Comment

Comment by Garlef

Interesting. I come from a math background and for me, monads capture a notion of "things that depend on a type". So for every type X you can think about Lists/Records/Trees/... of X. And if you're lucky this gadget let's you do two things: 1. You can turn every instance x of X into a primitive List/Record/Tree/... of Xs. 2. You can flatten Lists of Lists of Xs into plain Lists of Xs, etc.

This is something you see a lot once you know what you're looking for.

And if you're really lucky, these two are nicely compatible:

For example there are two ways to get from L(L(L(X))) to L(X): By either flattening first in the inside or first on the outside.

And for a monad, you get the same result either way.

And the computational part is then really more of a consequence: If you've got some function of type X->L(Y) and another one of type Y->L(Z) then you can compose them to a function of type X->L(Z).

parent Garlef 13 days ago

Discussion

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton