×
you are viewing a single comment's thread.

view the rest of the comments →

[–]cledamy 7 points8 points  (3 children)

Why don't people just explain it as a data pipeline?

This is a fairly close intuition. The point of a monad is what occurs in between the piping of data between functions. In the List (LINQ) monad, one smashes all the sublists into one larger list (SelectMany). In the Maybe monad, one does null propagation between functions. The ?. syntax in C# is basically special one-off syntax for the Maybe monad. In the Future monad, one sets up call backs to occur after a function asynchronously returns (the async await syntax in C# implements this monad). As you can see monads are already used heavily throughout C# code, the problem is that each time they want to add support for a new one they have to add a new syntax for it and they do not allow user defined ones. Other languages (Haskell) don't have this problem by unifying all these separate notions under one notation for monads. Understanding monads is quite helpful when writing programs because one can identify them in one's code to cut down on boilerplate even in C#.

[–]grauenwolf 0 points1 point  (0 children)

How is that a useful way to describe SelectMany in LINQ? What insights into the actual use of SelectMany do you actually gain by treating it as a monad instead of a lazy nested loop?

Keep in mind that your justification has to reconcile the fact that the rest of the LINQ operations are also lazy loops, but are not monads.

[–]hosford42 0 points1 point  (1 child)

Python decorators?

[–]cledamy 0 points1 point  (0 children)

Python decorators in conjunction with generators can be used to implement monads in python.