roam/20220310115927-monad.org

26 lines
1.2 KiB
Org Mode
Raw Normal View History

2022-03-10 17:01:36 +00:00
:PROPERTIES:
:ID: 8ee5037f-0673-4968-9ec4-184bf31dd72d
:END:
#+title: Monad
#+begin_quote
2022-03-12 23:33:26 +00:00
A monad is just a [[id:434ee61c-4461-424f-8dba-5c86ddb06c3c][monoid]] in the category of endofunctors.
2022-03-10 17:01:36 +00:00
#+end_quote
2022-03-16 23:56:10 +00:00
In [[id:9e68d422-cced-4177-96d1-90f777b9a493][Software Development]], this refers to an [[id:10eb4672-19ab-4275-a110-5446c96e7e24][Applicative Functor]] that provides a
method for applyling a function taking a bare value and returning a wrapped
value to a value already wrapped in that same type.
In [[id:9ac78677-2602-4a06-af0a-4ed82e98a9b6][Haskell]], the function to do this is called *bind*, and is available as the
infix operator ~>>=~. This method is useful for sequentially applying functions
which generate values wrapped in a Monad, abstracting away logic between each
sequential application. This behavior leads some people to refer to Monads as
"programmable semicolons", referring to imperative, C-like languages in which
each line of code is terminated with a semicolon and executed in sequence.
Haskell's "do notation" provides syntactic sugar for codifying such sequences.
#+caption: Bind function in Haskell
#+begin_src haskell :exports code
(>>=) :: Monad m => m a -> (a -> m b) -> m b
#+end_src