{"id":13617001,"url":"https://github.com/haskell/mtl","last_synced_at":"2025-05-15T13:09:03.573Z","repository":{"id":2302937,"uuid":"3261801","full_name":"haskell/mtl","owner":"haskell","description":"The Monad Transformer Library","archived":false,"fork":false,"pushed_at":"2025-05-08T18:29:56.000Z","size":273,"stargazers_count":379,"open_issues_count":32,"forks_count":67,"subscribers_count":23,"default_branch":"master","last_synced_at":"2025-05-13T14:16:39.767Z","etag":null,"topics":["haskell","monad","monad-transformers"],"latest_commit_sha":null,"homepage":"http://www.haskell.org/haskellwiki/Monad_Transformers","language":"Haskell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/haskell.png","metadata":{"files":{"readme":"README.markdown","changelog":"CHANGELOG.markdown","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2012-01-25T02:09:10.000Z","updated_at":"2025-05-08T18:30:02.000Z","dependencies_parsed_at":"2024-01-17T22:54:31.794Z","dependency_job_id":"fd60fbe7-fcd5-49e8-bfc1-ca39747dd13c","html_url":"https://github.com/haskell/mtl","commit_stats":{"total_commits":154,"total_committers":38,"mean_commits":4.052631578947368,"dds":0.7532467532467533,"last_synced_commit":"6be8cb55ca9a8bfa6111e3004e4b56b91ed5edcc"},"previous_names":[],"tags_count":19,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/haskell%2Fmtl","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/haskell%2Fmtl/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/haskell%2Fmtl/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/haskell%2Fmtl/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/haskell","download_url":"https://codeload.github.com/haskell/mtl/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254346623,"owners_count":22055808,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["haskell","monad","monad-transformers"],"created_at":"2024-08-01T20:01:35.762Z","updated_at":"2025-05-15T13:08:58.565Z","avatar_url":"https://github.com/haskell.png","language":"Haskell","funding_links":[],"categories":["Haskell"],"sub_categories":[],"readme":"# `mtl` [![Hackage](https://img.shields.io/hackage/v/mtl.svg)](https://hackage.haskell.org/package/mtl) [![Build Status](https://travis-ci.org/haskell/mtl.svg)](https://travis-ci.org/haskell/mtl)\n\nMTL is a collection of monad classes, extending the `transformers`\npackage, using functional dependencies for generic lifting of monadic\nactions.\n\n## Structure\n\nTransformers in MTL are divided into classes and data types. Classes\ndefine the monadic operations of transformers. Data types, generally\nfrom the `transformers` package, implement transformers, and MTL\nprovides instances for all the transformer type classes.\n\nMTL and `transformers` use a common module, data type, and function\nnaming scheme. As an example, let's imagine we have a transformer\n`Foo`.\n\nIn the `Control.Monad.Foo` module, we'd find:\n\n* A type class `MonadFoo` with the transformer operations.\n* A data type `FooT` with instances for all monad transformer classes.\n* Functions to run the transformed computation, e.g. `runFooT`. For\n  the actual transformers, there are usually a number of useful runner\n  functions.\n\n### Lifting\n\nWhen using monad transformers, you often need to \"lift\" a monadic\naction into your transformed monadic action. This is done using the\n`lift` function from `MonadTrans` in the `Control.Monad.Trans.Class`\nmodule:\n\n``` haskell\nlift :: (Monad m, MonadTrans t) =\u003e m a -\u003e t m a\n```\n\nThe action `m a` is lifted into the transformer action `t m a`.\n\nAs an example, here we lift an action of type `IO a` into an action of\ntype `ExceptT MyError IO a`:\n\n``` haskell\ndata MyError = EmptyLine\n\nmightFail :: ExceptT MyError IO ()\nmightFail = do\n  l \u003c- lift getLine\n  when (null l) (throwError EmptyLine)\n```\n\n### Transformers\n\nThe following outlines the available monad classes and transformers in\nMTL and `transformers`. For more details, and the corresponding\ndocumentation of the `mtl` version you are using, see [the\ndocumentation on Hackage](https://hackage.haskell.org/package/mtl).\n\n* `Control.Monad.Cont`\n\n    The Continuation monad transformer adds the ability to use\n    [continuation-passing style\n    (CPS)](https://en.wikipedia.org/wiki/Continuation-passing_style)\n    in a monadic computation. Continuations can be used to manipulate\n    the control flow of a program, e.g. early exit, error handling, or\n    suspending a computation.\n\n    - Class: `Control.Monad.Cont.Class.MonadCont`\n    - Transformer: `Control.Monad.Cont.ContT`\n\n* `Control.Monad.Error` (deprecated!)\n\n    The Error monad transformer has been deprecated in favor of\n    `Control.Monad.Except`.\n\n* `Control.Monad.Except`\n\n    The Except monad transformer adds the ability to fail with an\n    error in a monadic computation.\n\n    - Class: `Control.Monad.Except.Class.MonadError`\n    - Transformer: `Control.Monad.Except.ExceptT`\n\n* `Control.Monad.Identity`\n\n    The Identity monad transformer does not add any abilities to a\n    monad. It simply applies the bound function to its inner monad\n    without any modification.\n\n    - Transformer: `Control.Monad.Trans.Identity.IdentityT` (in the `transformers` package)\n    - Identity functor and monad: `Data.Functor.Identity.Identity` (in the `base` package)\n\n* `Control.Monad.RWS`\n\n    A convenient transformer that combines the Reader, Writer, and\n    State monad transformers.\n\n    - Lazy transformer: `Control.Monad.RWS.Lazy.RWST` (which is the default, exported by `Control.Monad.RWS`)\n    - Strict transformer: `Control.Monad.RWS.Strict.RWST`\n\n* `Control.Monad.Reader`\n\n    The Reader monad transformer represents a computation which can\n    read values from an environment.\n\n    - Class: `Control.Monad.Reader.Class.MonadReader`\n    - Transformer: `Control.Monad.Reader.ReaderT`\n\n* `Control.Monad.State`\n\n    The State monad transformer represents a computation which can\n    read and write internal state values. If you only need to _read_\n    values, you might want to use\n    [Reader](http://hackage.haskell.org/package/mtl/docs/Control-Monad-Reader.html)\n    instead.\n\n    - Class: `Control.Monad.State.Class.MonadState`\n    - Lazy transformer: `Control.Monad.State.Lazy.StateT` (the default, exported by `Control.Monad.State`)\n    - Strict transformer: `Control.Monad.State.Strict.StateT`\n\n* `Control.Monad.Writer`\n\n    The Writer monad transformer represents a computation that can\n    produce a stream of data in addition to the computed values. This\n    can be used to collect values in some data structure with a\n    `Monoid` instance. This can be used for things like logging and\n    accumulating values throughout a computation.\n\n    - Class: `Control.Monad.Writer.Class.MonadWriter`\n    - Lazy transformers: `Control.Monad.Writer.Lazy.WriterT`\n    - Strict transformers: `Control.Monad.Writer.Strict.WriterT`\n\n* `Control.Monad.Accum`\n\n    The `Accum` monad transformer represents a computation which\n    manages append-only state, or a writer that can read all\n    previous inputs. It binds a function to a monadic value by\n    lazily accumulating subcomputations via `(\u003c\u003e)`. For more general\n    access, use [State](https://hackage.haskell.org/package/transformers-0.6.0.4/docs/Control-Monad-Trans-State.html) instead.\n\n    - Class: `Control.Monad.Accum`\n    - Transformer: `Control.Monad.Trans.Accum.AccumT`\n\n* `Control.Monad.Select`\n\n    The `Select` monad transformer represents a computation which\n    can do backtracking search using a 'ranked' evaluation strategy.\n    Binding a function to a monad value chains together evaluation\n    strategies in the sense that the results of previous strategies\n    may influence subsequent rank and evaluation strategies in\n    subcomputations.\n\n    - Class: `Control.Monad.Select`\n    - Transformer: `Control.Monad.Trans.Select.SelectT`\n\n## Resources\n\n* [`mtl` on Hackage](http://hackage.haskell.org/package/mtl)\n* The [Monad Transformers](http://dev.stephendiehl.com/hask/#monad-transformers)\n  chapter in \"What I Wish I Knew When Learning Haskell\".\n* References:\n    - This package is inspired by the paper _Functional Programming\n      with Overloading and Higher-Order Polymorphism_, by Mark P\n      Jones, in _Advanced School of Functional Programming_, 1995\n      (\u003chttp://web.cecs.pdx.edu/~mpj/pubs/springschool.html\u003e).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhaskell%2Fmtl","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhaskell%2Fmtl","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhaskell%2Fmtl/lists"}