3 ms·
A bunch of languages have some special syntax to solve hairy problems. Async await, yield for generators, ? for dealing with errors in rust, etc. If those dea
by Tarean 7y ago
A bunch of languages have some special syntax to solve hairy problems. Async await, yield for generators, ? for dealing with errors in rust, etc.
If those deal with composition and variable scoping in an intuitive way it's a monad. This "intuitive way" is equivalent to changing block scoping in imperative languages.
{
let x = foo()
let y = bar(x)
let z = baz(x,y)
...
}
should stay equivalent to
{
let x = foo()
let z
{
let y = bar(x)
z = baz(x,y)
}
...
}
and you should be able to add empty scopes without changing anything so
{
foo()
}
should still equal
{
{}
foo()
{}
}
And that's the entire definition of monads. The abstract monad interface is useful to let users define new interpretations for the syntax sugar but not necessary when getting started with haskell - you will pick up intuitions while using it.