Monad -is:module

The Monad class defines the basic operations over a monad, a concept from a branch of mathematics known as category theory. From the perspective of a Haskell programmer, however, it is best to think of a monad as an abstract datatype of actions. Haskell's do expressions provide a convenient syntax for writing monadic expressions. Instances of Monad should satisfy the following: Furthermore, the Monad and Applicative operations should relate as follows: The above laws imply: and that pure and (<*>) satisfy the applicative functor laws. The instances of Monad for List, Maybe and IO defined in the Prelude satisfy these laws.
The Monad class defines the basic operations over a monad, a concept from a branch of mathematics known as category theory. From the perspective of a Haskell programmer, however, it is best to think of a monad as an abstract datatype of actions. Haskell's do expressions provide a convenient syntax for writing monadic expressions. Instances of Monad should satisfy the following: Furthermore, the Monad and Applicative operations should relate as follows: The above laws imply: and that pure and (<*>) satisfy the applicative functor laws. The instances of Monad for lists, Maybe and IO defined in the Prelude satisfy these laws.
The Monad class defines the basic operations over a monad, a concept from a branch of mathematics known as category theory. From the perspective of a Haskell programmer, however, it is best to think of a monad as an abstract datatype of actions. Haskell's do expressions provide a convenient syntax for writing monadic expressions. Instances of Monad should satisfy the following: Furthermore, the Monad and Applicative operations should relate as follows: The above laws imply: and that pure and (<*>) satisfy the applicative functor laws. The instances of Monad for lists, Maybe and IO defined in the Prelude satisfy these laws.
The Monad class defines the basic operations over a monad, a concept from a branch of mathematics known as category theory. From the perspective of a Haskell programmer, however, it is best to think of a monad as an abstract datatype of actions. Haskell's do expressions provide a convenient syntax for writing monadic expressions. Instances of Monad should satisfy the following laws: Furthermore, the Monad and Applicative operations should relate as follows: The above laws imply: and that pure and (<*>) satisfy the applicative functor laws. The instances of Monad for lists, Maybe and IO defined in the Prelude satisfy these laws.
The Monad class defines the basic operations over a monad, a concept from a branch of mathematics known as category theory. From the perspective of a Haskell programmer, however, it is best to think of a monad as an abstract datatype of actions. Haskell's do expressions provide a convenient syntax for writing monadic expressions. Instances of Monad should satisfy the following laws: Furthermore, the Monad and Applicative operations should relate as follows: The above laws imply: and that pure and (<*>) satisfy the applicative functor laws. The instances of Monad for lists, Maybe and IO defined in the Prelude satisfy these laws.
Properties to check that the Monad m satisfies the monad properties
The program we need to crack. Note that different users get different programs on the Advent-Of-Code site, so this is simply one example. You can simply cut-and-paste your version instead. (Don't forget the pragma NegativeLiterals to GHC so add x -1 parses correctly as add x (-1).)
When a value is bound in do-notation, the pattern on the left hand side of <- might not match. In this case, this class provides a function to recover. A Monad without a MonadFail instance may only be used in conjunction with pattern that always match, such as newtypes, tuples, data types with only a single data constructor, and irrefutable patterns (~pat). Instances of MonadFail should satisfy the following law: fail s should be a left zero for >>=,
fail s >>= f  =  fail s
If your Monad is also MonadPlus, a popular definition is
fail _ = mzero
fail s should be an action that runs in the monad itself, not an exception (except in instances of MonadIO). In particular, fail should not be implemented in terms of error.
Monads that also support choice and failure.
Monads having fixed points with a 'knot-tying' semantics. Instances of MonadFix should satisfy the following laws: This class is used in the translation of the recursive do notation supported by GHC and Hugs.
Monads in which IO computations may be embedded. Any monad built by applying a sequence of monad transformers to the IO monad will be an instance of this class. Instances should satisfy the following laws, which state that liftIO is a transformer of monads:
Instances should satisfy the laws:
The capability to accumulate. This can be seen in one of two ways:

Laws

accum should obey the following:
  1. accum (const (x, mempty)) = pure x
  2. accum f *> accum g = accum $ acc -> let (_, v) = f acc (res, w) = g (acc <> v) in (res, v <> w)
If you choose to define look and add instead, their definitions must obey the following:
  1. look *> look = look
  2. add mempty = pure ()
  3. add x *> add y = add (x <> y)
  4. add x *> look = look >>= w -> add x $> w <> x
If you want to define both, the relationship between them is as follows. These are also the default definitions.
  1. look = accum $ acc -> (acc, mempty)
  2. add x = accum $ acc -> ((), x)
  3. accum f = look >>= acc -> let (res, v) = f acc in add v $> res
The strategy of combining computations that can throw exceptions by bypassing bound functions from the point an exception is thrown to the point that it is handled. Is parameterized over the type of error information and the monad type constructor. It is common to use Either String as the monad type constructor for an error monad in which error descriptions take the form of strings. In that case and many other common cases the resulting monad is already defined as an instance of the MonadError class. You can also define your own error type and/or use a monad type constructor other than Either String or Either IOError. In these cases you will have to explicitly define instances of the MonadError class. (If you are using the deprecated Control.Monad.Error or Control.Monad.Trans.Error, you may also have to define an Error instance.)
See examples in Control.Monad.Reader. Note, the partially applied function type (->) r is a simple reader monad. See the instance declaration below.
The capability to search with backtracking. Essentially describes a 'policy function': given the state of the search (and a 'ranking' or 'evaluation' of each possible result so far), pick the result that's currently best.

Laws

Any instance of MonadSelect must follow these laws:
Minimal definition is either both of get and put or just state