monads are not that hard.
if you know imperative programming -- "do this, then do that" -- then you are already acquainted with them.
you're a fish, and monads are the sea.
monads are not that hard.
if you know imperative programming -- "do this, then do that" -- then you are already acquainted with them.
you're a fish, and monads are the sea.
we start with free monads.
a free monad is an imperative programming language with some builtin operations. the choice of operations determine which monad / language you get. the statements in this language are:
- perform one of the builtin operations, which can take some input values and produce one output value.
- calculate a new value using a pure function, e.g. squaring a number.
- decide between different courses of actions based on a value, e.g. switch or if statements.
- return a value.
notice the free monad describes an imperative language, but when we use a monad, what we're actually working with is a generic type that represents programs in that language.
e.g. suppose the monad is called Foo, then Foo(Int) and Foo(String) and Foo(Float) are all types that represent programs in the Foo language. (*your notation for generic types may vary.)
in particular, Foo(T) is the type of programs in the Foo language where the final "return" statement has a value of type T.
(it's getting late, i will probably come back to this thread tomorrow)