3 ms·
There's a problem here as the author himself notes. I can provide you a simple example of a function with monadic interface, you will understand it any langua
by aszen 5y ago
There's a problem here as the author himself notes.
I can provide you a simple example of a function with monadic interface, you will understand it any language but that will not actually help you to conceptualize the idea of monads and influence your thinking.
You will just think that's simple, whats the fuss about it and miss the pattern altogether.
Imagine asking the user to provide a number, in most languages you will get a `string | null` value and you wish to get a real number from it by parsing the string if the user entered it.
In this case assuming you have a function `parseNo` that goes from `string -> int | null` you can create a special function which takes a `string | null` value along with the `parseNo` function and gives you back `int | null`. S
Turns out that function can be defined for many different data types and it has special useful properties.
In this case it allows us to compose functions neatly, without having to do a whole bunch of null checks.
But in other scenarios it can do a lot more.
- _ph_ 5y agoSounds like you are describing high order functions as they are known from Lisp?
- aszen 5y agoYes higher order functions. A function that takes a function as an argument or returns a function. In lisp you can think of a higher order function as taking data, processing it and then returning it just like any other normal function because code is data.