Hacker News new | ask | show | jobs
by kfixjviv 1028 days ago
The main reason that monads are restricted to fancy languages like Haskell is that the type system has to support their definition.

There are some examples of attempted implementations the list monad in other languages on RosettaCode https://rosettacode.org/wiki/Monads/List_monad

Caveat emptor, though. A lot of that page is erroneous.

A few years ago I fixed up the definition for F#, which is perhaps the closest thing to a language for ordinary Joes in which true monadic style can be defined/achieved.

1 comments

Monads are a concept in types and a specific theory but if you throw the rigid definition away can't they be done anywhere? For example, if I have three RaspberryPi's, isn't there a way I could compose them as monads?

That is what I mean - it isn't a fair thing for me to say - but I feel like they would be so much more tangible if we could think about them as literal Things like this. Which is why my original example was composition of Programs instead of composition in a specific Programming Language.

Each Raspberry Pi could perform a function that was notionally passed to the monadic bind operator, but really a monad is the rules under which the Raspberry Pis would be connected.

From Wadler's paper "The Essence of Functional Programming":

"2.1 What is a monad?

For our purposes, a monad is a triple (M,unitM,bindM) consisting of a type constructor M and a pair of polymorphic functions.

unitM :: a-> M a

bindM :: M a-> (a-> M b)-> M b

These functions must satisfy three laws, which are discussed in Section 2.10."

So the monad is a functor plus a few operations and laws. It is an algebraic structure, not a type of object or function.

By the way, "throwing the rigid definition away" would be completely missing the point. The rigid definition is the essence of monads.
People who think they hate maths will always try to get rid of the maths and tell themselves that that makes the maths way better.
It's important to me because if the pattern was actually useful then we should be able to use it anywhere and talk about it. It seems obvious that the pipe "workflow" pattern as they call it isn't the end-all for program composition - so how can we fix and expand it? It seems fixable.

Another context question: How would you define a monad in Microsoft Excel? For context, that is my favorite programming language. It seems perfectly capable at doing strong monad composition better than a Linux shell.

I just want monads be real and tangible! Examples in reality instead of Math.

You are going to be disappointed.

What on earth makes you convinced that a monad can be implemented in Excel? You don't understand what a monad is, so you can't know whether Excel is "perfectly capable" of it or not.

Read a bunch of monad tutorials, learn Haskell, hey, even develop some "mathematical maturity" if you can get over your disdain for math. That is the way to make progress.

It's not helpful to want monads to be tangible objects. It doesn't matter how much you want it. The world doesn't work like that.

> What on earth makes you convinced that a monad can be implemented in Excel

True monads can't even be implemented in Haskell. But if we're being practical, you can totally implement monad-like things in Excel. It's almost impossible not to implement monad-like things when building anything non-trivial.

I don't think making this claim is helpful. Monads aren't found everywhere in code. Solving a problem which could be solved by monads doesn't automatically lead to code that works in a monad-like way, not in any meaningful sense.
My conviction goes like this:

1. Excel doesn't use rigid types so we can throw away all the rigid math stuff (this is where our perspectives diverge into non-sense)

2. Each Cell is a Monad

3. Each monad can be composed and reflect eachother better than any other programming language (more than Pipes like my original 1 | 2 | 3 example)

"Each cell is a monad" makes as much sense as "41 is a commutativity".
> It is an algebraic structure, not a type of object or function.

Also therefore it is not that "monads can be composed with monads". Only Functions can, bhe composed. Especially functions which are the unitM() or bindM of some monad.