3 ms·
This bit of the Guix documentation provides a better explanation of why monads are useful than I could give: The procedures that operate on the store descr
by davexunit 11y ago
This bit of the Guix documentation provides a better explanation of why monads are useful than I could give:
The procedures that operate on the store described in the previous
sections all take an open connection to the build daemon as their
first argument. Although the underlying model is functional, they
either have side effects or depend on the current state of the
store.
The former is inconvenient: the connection to the build daemon has
to be carried around in all those functions, making it impossible
to compose functions that do not take that parameter with
functions that do. The latter can be problematic: since store
operations have side effects and/or depend on external state, they
have to be properly sequenced.
This is where the (guix monads) module comes in. This module
provides a framework for working with monads, and a particularly
useful monad for our uses, the store monad. Monads are a construct
that allows two things: associating “context” with values (in our
case, the context is the store), and building sequences of
computations (here computations include accesses to the store.)
Values in a monad—values that carry this additional context—are
called monadic values; procedures that return such values are
called monadic procedures.
https://gnu.org/software/guix/manual/html_node/The-Store-Monad.html#The-Store-Monad https://gnu.org/software/guix/manual/html_node/The-Store-Mon...