A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://wiki.haskell.org/Monad_(sans_metaphors) below:

Monad (sans metaphors) - HaskellWiki

Think of a monad as a spacesuit full of nuclear waste in the ocean next to a container of apples. Now, you can't put oranges in the spacesuit or the nuclear waste falls in the ocean, but the apples are carried around anyway, and you just take what you need.

Don Stewart.

Introduction

Many discussions of Haskell monads seek to explain them through the use of a variety of metaphors. This page attempts to simply provide a more technical yet straightforward description of monads as defined by Haskell.

So what is a monad?

In Haskell, a monad is a type constructor with two operations, implementing a standard interface and following a few simple rules:

The monadic interface gives you two operations:

The chaining explicitly caters for information flowing from the first to the second parameter of (>>=).

The monad laws tell you two useful facts about monadic things thrown together in that way: whatever it is the monad does, anything just thrown into it will take no part in that action, and whichever way you use that chaining operation, the structure of chaining is irrelevant - only the ordering of chained monadic things matters.

There are usually other ways to create "primitive" monadic things, which can be combined into complex monadic structures using the operations of the monadic interface.

There usually is an abstract way to interpret monadic structures built in this way - a run operation of some kind. Examples include:

Sometimes the monadic type provides the run operation as part of its interface:

Original source

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4