I'm currently reading up on category theory basics and try to make sense of the names Haskell assigns to monad operations, semantically.
All material I've come through refers to return
as the unit map and join
as the multiplication map (I'm OK with the name "join"). For >>=
or bind
I haven't even (yet) found a name common in math. Rather I've come across its flipped form, lift
or -*, which in turn makes sense to me.
Actual questions (tldr):
The mathematician Roger Godement was the first to formulate the concept of a monad (dubbing it a "standard construction") in the late 1950s, though the term "monad" that came to dominate was popularized by category-theorist Saunders Mac Lane.
Monads are simply a way to wrapping things and provide methods to do operations on the wrapped stuff without unwrapping it. For example, you can create a type to wrap another one, in Haskell: data Wrapped a = Wrap a. To wrap stuff we define return :: a -> Wrapped a return x = Wrap x.
A monad is an algebraic structure in category theory, and in Haskell it is used to describe computations as sequences of steps, and to handle side effects such as state and IO. Monads are abstract, and they have many useful concrete instances. Monads provide a way to structure a program.
Using Maybe is a good way to deal with errors or exceptional cases without resorting to drastic measures such as error . The Maybe type is also a monad. It is a simple kind of error monad, where all errors are represented by Nothing . A richer error monad can be built using the Either type.
Both names come from programming, rather than math. return
, being used as the last statement of the do
expression, makes it look very imperative: do {do_something; return result}
. bind
's name comes from its do
translation: action >>= \x -> something
translates to do {x <- action; something}
, which looks like x
is bound to the value returned from action
.
As for bind
's analog in math world, google "Kleisli triple".
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With