Skip to content

Instantly share code, notes, and snippets.

@psenger
Last active December 18, 2023 06:32
Show Gist options
  • Save psenger/886c014fede3fbcebf4862964abfc9e2 to your computer and use it in GitHub Desktop.
Save psenger/886c014fede3fbcebf4862964abfc9e2 to your computer and use it in GitHub Desktop.
[Monad and Curry] #functionalProgramming

Curry

Currying is the process of turning a function that expects multiple parameters into one that, when supplied fewer parameters, returns a new function that awaits the remaining ones. [1]


[1] https://fr.umio.us/favoring-curry/

Monad

In functional programming, a monad is a concept used to manage computations that involve side effects or computations that may fail. It provides a structured way to handle these effects while maintaining the functional programming principles.

At its core, a monad is a data structure that wraps a value and defines certain operations on that value. These operations allow us to compose and sequence computations while keeping track of the effects.

The concept of a monad is not specifically tied to the notion of state. In fact, different types of monads can represent and handle various kinds of computations or effects.

The state is just one example of an effect that can be managed using a monad. Other effects include handling exceptions, non-determinism, input/output operations, and more. Each effect can be encapsulated within its own monad, allowing for composability and structured handling of those effects.

To clarify, a monad is essentially a combination of a value and a set of operations or functions that allow you to manipulate and compose computations involving that value while managing a specific effect. The monad provides a way to control the flow and propagation of that effect within a functional programming paradigm.

So, while a monad can handle state, it can also handle various other effects or computations, depending on the specific monad's purpose and design. The state monad, in particular, would focus on managing state-related operations and maintaining immutability and referential transparency. However, the concept of a monad is not limited to state handling alone.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment