6 ms·
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
by kfixjviv 3y 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 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.
- koolala 3y agoMonads 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.
- kfixjviv 3y agoEach 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.
- kfixjviv 3y agoBy the way, "throwing the rigid definition away" would be completely missing the point. The rigid definition is the essence of monads.
- epgui 3y agoPeople who think they hate maths will always try to get rid of the maths and tell themselves that that makes the maths way better.
- koolala 3y agoIt'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.
- kfixjviv 3y agoYou 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.
- koolala 3y agoMy 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)
- rbonvall 3y ago"Each cell is a monad" makes as much sense as "41 is a commutativity".
- koolala 3y agoWhat I mean is, they can easily be used as monads - and in fact every Excel user might do so without even knowing what a monad is. Like 41 is used in commutative expressions all the time by people who don't even know what communitivity or associativity mathematically is and that is a good thing! It means its useful and intuitive! That's why I wish we could throw out the Math, if we can't even use Monads without mathematically knowing they are Monads then no one is ever going to be using them. There must be a way that these patterns can become so intuitive, like Pipes (weak) and Excel (strong) that they speak for themselves and become tangible.
- galaxyLogic 3y ago> 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.