All Projects → haskell → Mtl

haskell / Mtl

Licence: other
The Monad Transformer Library

Programming Languages

haskell
3896 projects

Labels

Projects that are alternatives of or similar to Mtl

Expected
What did you expect?
Stars: ✭ 113 (-55.16%)
Mutual labels:  monad
Fpgo
Monad, Functional Programming features for Golang
Stars: ✭ 165 (-34.52%)
Mutual labels:  monad
Bastet
A ReasonML/Ocaml library for category theory and abstract algebra
Stars: ✭ 200 (-20.63%)
Mutual labels:  monad
Dunai
Classic and Arrowized Functional Reactive Programming, Reactive Programming, and Stream programming, all via Monadic Stream Functions
Stars: ✭ 115 (-54.37%)
Mutual labels:  monad
Functional Promises
Write code like a story w/ a powerful Fluent (function chaining) API
Stars: ✭ 141 (-44.05%)
Mutual labels:  monad
Mostly Adequate Guide Chinese
函数式编程指北中文版
Stars: ✭ 2,093 (+730.56%)
Mutual labels:  monad
Masala Parser
Javascript Generalized Parser Combinators
Stars: ✭ 110 (-56.35%)
Mutual labels:  monad
Cats Mtl
cats transformer type classes.
Stars: ✭ 238 (-5.56%)
Mutual labels:  monad
Burrido
Do-notation for JavaScript
Stars: ✭ 150 (-40.48%)
Mutual labels:  monad
Funcadelic.js
Functional programming and category theory for everyday JavaScript development
Stars: ✭ 183 (-27.38%)
Mutual labels:  monad
Alembic
⚗️ Functional JSON Parser - Linux Ready 🐧
Stars: ✭ 115 (-54.37%)
Mutual labels:  monad
Rubico
[a]synchronous functional programming
Stars: ✭ 133 (-47.22%)
Mutual labels:  monad
Functional Examples
Examples with Functional JavaScript, following Professor Frisby's course
Stars: ✭ 179 (-28.97%)
Mutual labels:  monad
Mayre
Maybe render a React component, maybe not 😮
Stars: ✭ 114 (-54.76%)
Mutual labels:  monad
Dsl.scala
A framework to create embedded Domain-Specific Languages in Scala
Stars: ✭ 220 (-12.7%)
Mutual labels:  monad
F
Functional stuff for Python
Stars: ✭ 113 (-55.16%)
Mutual labels:  monad
Swift Adventures In Monad Land
A Swift adventure with Optionals, Monads, bananas and squirrels
Stars: ✭ 166 (-34.13%)
Mutual labels:  monad
Each
A macro library that converts native imperative syntax to scalaz's monadic expressions
Stars: ✭ 245 (-2.78%)
Mutual labels:  monad
Monadless
Syntactic sugar for monad composition in Scala
Stars: ✭ 231 (-8.33%)
Mutual labels:  monad
Fluture
🦋 Fantasy Land compliant (monadic) alternative to Promises
Stars: ✭ 2,249 (+792.46%)
Mutual labels:  monad

mtl Hackage Build Status

MTL is a collection of monad classes, extending the transformers package, using functional dependencies for generic lifting of monadic actions.

Structure

Transformers in MTL are divided into classes and data types. Classes define the monadic operations of transformers. Data types, generally from the transformers package, implement transformers, and MTL provides instances for all the transformer type classes.

MTL and transformers use a common module, data type, and function naming scheme. As an example, let's imagine we have a transformer Foo.

In the Control.Monad.Foo module, we'd find:

  • A type class MonadFoo with the transformer operations.
  • A data type FooT with instances for all monad transformer classes.
  • Functions to run the transformed computation, e.g. runFooT. For the actual transformers, there are usually a number of useful runner functions.

Lifting

When using monad transformers, you often need to "lift" a monadic action into your transformed monadic action. This is done using the lift function from MonadTrans in the Control.Monad.Trans.Class module:

lift :: (Monad m, MonadTrans t) => m a -> t m a

The action m a is lifted into the transformer action t m a.

As an example, here we lift an action of type IO a into an action of type ExceptT MyError IO a:

data MyError = EmptyLine

mightFail :: ExceptT MyError IO ()
mightFail = do
  l <- lift getLine
  when (null l) (throwError EmptyLine)

Transformers

The following outlines the available monad classes and transformers in MTL and transformers. For more details, and the corresponding documentation of the mtl version you are using, see the documentation on Hackage.

  • Control.Monad.Cont

    The Continuation monad transformer adds the ability to use continuation-passing style (CPS) in a monadic computation. Continuations can be used to manipulate the control flow of a program, e.g. early exit, error handling, or suspending a computation.

    • Class: Control.Monad.Cont.Class.MonadCont
    • Transformer: Control.Monad.Cont.ContT
  • Control.Monad.Error (deprecated!)

    The Error monad transformer has been deprecated in favor of Control.Monad.Except.

  • Control.Monad.Except

    The Except monad transformer adds the ability to fail with an error in a monadic computation.

    • Class: Control.Monad.Except.Class.MonadError
    • Transformer: Control.Monad.Except.ExceptT
  • Control.Monad.Identity

    The Identity monad transformer does not add any abilities to a monad. It simply applies the bound function to its inner monad without any modification.

    • Transformer: Control.Monad.Trans.Identity.IdentityT (in the transformers package)
    • Identity functor and monad: Data.Functor.Identity.Identity (in the base package)
  • Control.Monad.List

    This transformer combines the list monad with another monad. Note that this does not yield a monad unless the inner monad is commutative.

    • Transformer: Control.Monad.List.ListT
  • Control.Monad.RWS

    A convenient transformer that combines the Reader, Writer, and State monad transformers.

    • Lazy transformer: Control.Monad.RWS.Lazy.RWST (which is the default, exported by Control.Monad.RWS)
    • Strict transformer: Control.Monad.RWS.Strict.RWST
  • Control.Monad.Reader

    The Reader monad transformer represents a computation which can read values from an environment.

    • Class: Control.Monad.Reader.Class.MonadReader
    • Transformer: Control.Monad.Reader.ReaderT
  • Control.Monad.State

    The State monad transformer represents a computation which can read and write internal state values. If you only need to read values, you might want to use Reader instead.

    • Class: Control.Monad.State.Class.MonadState
    • Lazy transformer: Control.Monad.State.Lazy.StateT (the default, exported by Control.Monad.State)
    • Strict transformer: Control.Monad.State.Strict.StateT
  • Control.Monad.Writer

    The Writer monad transformer represents a computation that can produce a stream of data in addition to the computed values. This can be used to collect values in some data structure with a Monoid instance. This can be used for things like logging and accumulating values throughout a computation.

    • Class: Control.Monad.Writer.Class.MonadWriter
    • Lazy transformers: Control.Monad.Writer.Lazy.WriterT
    • Strict transformers: Control.Monad.Writer.Strict.WriterT

Resources

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].