<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<!--Rendered using the Haskell Html Library v0.2-->
<HTML
><HEAD
><META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=UTF-8"
><TITLE
>Control.Monad.Identity</TITLE
>

<style type="text/css">
/* -------- Global things --------- */

BODY { 
  background-color: #ffffff;
  color: #000000;
  font-family: sans-serif;
  } 

A:link    { color: #0000e0; text-decoration: none }
A:visited { color: #0000a0; text-decoration: none }
A:hover   { background-color: #e0e0ff; text-decoration: none }

TABLE.vanilla {
  width: 100%;
  border-width: 0px;
  /* I can't seem to specify cellspacing or cellpadding properly using CSS... */
}

TABLE.vanilla2 {
  border-width: 0px;
}

/* <TT> font is a little too small in MSIE */
TT  { font-size: 100%; }
PRE { font-size: 100%; }

LI P { margin: 0pt } 

TD {
  border-width: 0px;
}

TABLE.narrow {
  border-width: 0px;
}

TD.s8  {  height: 8px;  }
TD.s15 {  height: 15px; }

SPAN.keyword { text-decoration: underline; }

/* Resize the buttom image to match the text size */
IMG.coll { width : 0.75em; height: 0.75em; margin-bottom: 0; margin-right: 0.5em }

/* --------- Contents page ---------- */

DIV.node {
  padding-left: 3em;
}

DIV.cnode {
  padding-left: 1.75em;
}

SPAN.pkg {
  position: absolute;
  left: 50em;
}

/* --------- Documentation elements ---------- */

TD.children {
  padding-left: 25px;
  }

TD.synopsis {
  padding: 2px;
  background-color: #f0f0f0;
  font-family: monospace
 }

TD.decl { 
  padding: 2px;
  background-color: #f0f0f0; 
  font-family: monospace;
  vertical-align: top;
  }

/* 
  arg is just like decl, except that wrapping is not allowed.  It is
  used for function and constructor arguments which have a text box
  to the right, where if wrapping is allowed the text box squashes up
  the declaration by wrapping it.
*/
TD.arg { 
  padding: 2px;
  background-color: #f0f0f0; 
  font-family: monospace;
  vertical-align: top;
  white-space: nowrap;
  }

TD.recfield { padding-left: 20px }

TD.doc  { 
  padding-top: 2px;
  padding-left: 10px;
  }

TD.ndoc  { 
  padding: 2px;
  }

TD.rdoc  { 
  padding: 2px;
  padding-left: 10px;
  width: 100%;
  }

TD.body  { 
  padding-left: 10px
  }

TD.pkg {
  width: 100%;
  padding-left: 10px
}

TD.indexentry {
  vertical-align: top;
  padding-right: 10px
  }

TD.indexannot {
  vertical-align: top;
  padding-left: 20px;
  white-space: nowrap
  }

TD.indexlinks {
  width: 100%
  }

/* ------- Section Headings ------- */

TD.section1 {
  padding-top: 15px;
  font-weight: bold;
  font-size: 150%
  }

TD.section2 {
  padding-top: 10px;
  font-weight: bold;
  font-size: 130%
  }

TD.section3 {
  padding-top: 5px;
  font-weight: bold;
  font-size: 110%
  }

TD.section4 {
  font-weight: bold;
  font-size: 100%
  }

/* -------------- The title bar at the top of the page */

TD.infohead {
  color: #ffffff;
  font-weight: bold;
  padding-right: 10px;
  text-align: left;
}

TD.infoval {
  color: #ffffff;
  padding-right: 10px;
  text-align: left;
}

TD.topbar {
  background-color: #000099;
  padding: 5px;
}

TD.title {
  color: #ffffff;
  padding-left: 10px;
  width: 100%
  }

TD.topbut {
  padding-left: 5px;
  padding-right: 5px;
  border-left-width: 1px;
  border-left-color: #ffffff;
  border-left-style: solid;
  white-space: nowrap;
  }

TD.topbut A:link {
  color: #ffffff
  }

TD.topbut A:visited {
  color: #ffff00
  }

TD.topbut A:hover {
  background-color: #6060ff;
  }

TD.topbut:hover {
  background-color: #6060ff
  }

TD.modulebar { 
  background-color: #0077dd;
  padding: 5px;
  border-top-width: 1px;
  border-top-color: #ffffff;
  border-top-style: solid;
  }

/* --------- The page footer --------- */

TD.botbar {
  background-color: #000099;
  color: #ffffff;
  padding: 5px
  }
TD.botbar A:link {
  color: #ffffff;
  text-decoration: underline
  }
TD.botbar A:visited {
  color: #ffff00
  }
TD.botbar A:hover {
  background-color: #6060ff
  }

</style>

<SCRIPT SRC="haddock.js" TYPE="text/javascript"
></SCRIPT
></HEAD
><BODY
><TABLE CLASS="vanilla" CELLSPACING="0" CELLPADDING="0"
><TR
><TD CLASS="topbar"
><TABLE CLASS="vanilla" CELLSPACING="0" CELLPADDING="0"
><TR
><TD
><IMG SRC="haskell_icon.gif" WIDTH="16" HEIGHT="16" ALT=" "
></TD
><TD CLASS="title"
></TD
><TD CLASS="topbut"
><A HREF="index.html"
>Contents</A
></TD
><TD CLASS="topbut"
><A HREF="doc-index.html"
>Index</A
></TD
></TR
></TABLE
></TD
></TR
><TR
><TD CLASS="modulebar"
><TABLE CLASS="vanilla" CELLSPACING="0" CELLPADDING="0"
><TR
><TD
><FONT SIZE="6"
>Control.Monad.Identity</FONT
></TD
><TD ALIGN="right"
><TABLE CLASS="narrow" CELLSPACING="0" CELLPADDING="0"
><TR
><TD CLASS="infohead"
>Portability</TD
><TD CLASS="infoval"
>portable</TD
></TR
><TR
><TD CLASS="infohead"
>Stability</TD
><TD CLASS="infoval"
>experimental</TD
></TR
><TR
><TD CLASS="infohead"
>Maintainer</TD
><TD CLASS="infoval"
>libraries@haskell.org</TD
></TR
></TABLE
></TD
></TR
></TABLE
></TD
></TR
><TR
><TD CLASS="s15"
></TD
></TR
><TR
><TD
><TABLE CLASS="vanilla" CELLSPACING="0" CELLPADDING="0"
></TABLE
></TD
></TR
><TR
><TD CLASS="s15"
></TD
></TR
><TR
><TD CLASS="section1"
>Description</TD
></TR
><TR
><TD CLASS="doc"
><DL
><DT
>Computation type:</DT
><DD
> Simple function application.
</DD
><DT
>Binding strategy:</DT
><DD
> The bound function is applied to the input value.
<TT
><TT
><A HREF="Control-Monad-Identity.html#t%3AIdentity"
>Identity</A
></TT
> x &gt;&gt;= f == <TT
><A HREF="Control-Monad-Identity.html#t%3AIdentity"
>Identity</A
></TT
> (f x)</TT
>
</DD
><DT
>Useful for:</DT
><DD
> Monads can be derived from monad transformers applied to the
<TT
><A HREF="Control-Monad-Identity.html#t%3AIdentity"
>Identity</A
></TT
> monad.
</DD
><DT
>Zero and plus:</DT
><DD
> None.
</DD
><DT
>Example type:</DT
><DD
> <TT
><TT
><A HREF="Control-Monad-Identity.html#t%3AIdentity"
>Identity</A
></TT
> a</TT
>
</DD
></DL
><P
>The <TT
>Identity</TT
> monad is a monad that does not embody any computational strategy.
It simply applies the bound function to its input without any modification.
Computationally, there is no reason to use the <TT
>Identity</TT
> monad
instead of the much simpler act of simply applying functions to their arguments.
The purpose of the <TT
>Identity</TT
> monad is its fundamental role in the theory
of monad transformers.
Any monad transformer applied to the <TT
>Identity</TT
> monad yields a non-transformer
version of that monad.
</P
><P
>Inspired by the paper
  <EM
>Functional Programming with Overloading and
      Higher-Order Polymorphism</EM
>, 
    Mark P Jones (<A HREF="http://www.cse.ogi.edu/~mpj/"
>http://www.cse.ogi.edu/~mpj/</A
>)
          Advanced School of Functional Programming, 1995.
</P
></TD
></TR
><TR
><TD CLASS="s15"
></TD
></TR
><TR
><TD CLASS="section1"
>Synopsis</TD
></TR
><TR
><TD CLASS="s15"
></TD
></TR
><TR
><TD CLASS="body"
><TABLE CLASS="vanilla" CELLSPACING="0" CELLPADDING="0"
><TR
><TD CLASS="decl"
><SPAN CLASS="keyword"
>newtype</SPAN
> <A HREF="#t%3AIdentity"
>Identity</A
> a = <A HREF="#v%3AIdentity"
>Identity</A
> {<TABLE CLASS="vanilla" CELLSPACING="0" CELLPADDING="0"
><TR
><TD CLASS="recfield"
><A HREF="#v%3ArunIdentity"
>runIdentity</A
> :: a</TD
></TR
></TABLE
>}</TD
></TR
></TABLE
></TD
></TR
><TR
><TD CLASS="s15"
></TD
></TR
><TR
><TD CLASS="section1"
>Documentation</TD
></TR
><TR
><TD CLASS="s15"
></TD
></TR
><TR
><TD CLASS="decl"
><SPAN CLASS="keyword"
>newtype</SPAN
> <A NAME="t%3AIdentity"
></A
><B
>Identity</B
> a</TD
></TR
><TR
><TD CLASS="body"
><TABLE CLASS="vanilla" CELLSPACING="0" CELLPADDING="0"
><TR
><TD CLASS="ndoc"
><P
>Identity wrapper.
Abstraction for wrapping up a object.
If you have an monadic function, say:
</P
><PRE
>   example :: Int -&gt; Identity Int
   example x = return (x*x)
</PRE
><P
>you can &quot;run&quot; it, using
</P
><PRE
> Main&gt; runIdentity (example 42)
 1764 :: Int
</PRE
><P
>A typical use of the Identity monad is to derive a monad
from a monad transformer.
</P
><PRE
>
-- derive the <TT
><A HREF="Control-Monad-State.html#t%3AState"
>State</A
></TT
> monad using the <TT
><A HREF="Control-Monad-State.html#t%3AStateT"
>StateT</A
></TT
> monad transformer
type <TT
><A HREF="Control-Monad-State.html#t%3AState"
>State</A
></TT
> s a = <TT
><A HREF="Control-Monad-State.html#t%3AStateT"
>StateT</A
></TT
> s <TT
><A HREF="Control-Monad-Identity.html#t%3AIdentity"
>Identity</A
></TT
> a
</PRE
><P
>The <TT
><TT
><A HREF="Control-Monad-Identity.html#v%3ArunIdentity"
>runIdentity</A
></TT
></TT
> label is used in the type definition because it follows
a style of monad definition that explicitly represents monad values as
computations. In this style, a monadic computation is built up using the monadic
operators and then the value of the computation is extracted
using the <TT
>run******</TT
> function.
Because the <TT
>Identity</TT
> monad does not do any computation, its definition
is trivial.
For a better example of this style of monad,
see the <TT
><TT
><A HREF="Control-Monad-State.html#t%3AState"
>State</A
></TT
></TT
> monad.
</P
></TD
></TR
><TR
><TD CLASS="section4"
>Constructors</TD
></TR
><TR
><TD CLASS="body"
><TABLE CLASS="vanilla" CELLSPACING="5" CELLPADDING="0"
><TR
><TD CLASS="arg"
><A NAME="v%3AIdentity"
></A
><B
>Identity</B
></TD
><TD CLASS="rdoc"
></TD
></TR
><TR
><TD CLASS="body" COLSPAN="2"
><TABLE CLASS="vanilla" CELLSPACING="1" CELLPADDING="0"
><TR
><TD CLASS="arg"
><A NAME="v%3ArunIdentity"
></A
><B
>runIdentity</B
> :: a</TD
><TD CLASS="rdoc"
></TD
></TR
></TABLE
></TD
></TR
></TABLE
></TD
></TR
><TR
><TD CLASS="section4"
><IMG SRC="minus.gif" CLASS="coll" ONCLICK="toggle(this,'i:Identity')" ALT="show/hide"
> Instances</TD
></TR
><TR
><TD CLASS="body"
><DIV ID="i:Identity" STYLE="display:block;"
><TABLE CLASS="vanilla" CELLSPACING="1" CELLPADDING="0"
><TR
><TD CLASS="decl"
>Functor <A HREF="Control-Monad-Identity.html#t%3AIdentity"
>Identity</A
></TD
></TR
><TR
><TD CLASS="decl"
>Monad <A HREF="Control-Monad-Identity.html#t%3AIdentity"
>Identity</A
></TD
></TR
><TR
><TD CLASS="decl"
>MonadFix <A HREF="Control-Monad-Identity.html#t%3AIdentity"
>Identity</A
></TD
></TR
></TABLE
></DIV
></TD
></TR
></TABLE
></TD
></TR
><TR
><TD CLASS="s15"
></TD
></TR
><TR
><TD CLASS="botbar"
>Produced by <A HREF="http://www.haskell.org/haddock/"
>Haddock</A
> version 0.7</TD
></TR
></TABLE
></BODY
></HTML
>