<!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.Instances</TITLE ><LINK HREF="haddock.css" REL="stylesheet" TYPE="text/css" ><SCRIPT SRC="haddock-util.js" TYPE="text/javascript" ></SCRIPT ><SCRIPT TYPE="text/javascript" >window.onload = function () {setSynopsis("mini_Control-Monad-Instances.html")};</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" >base-4.1.0.0: Basic libraries</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.Instances</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" >provisional</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 CLASS="section1" >Description</TD ></TR ><TR ><TD CLASS="doc" ><TT ><A HREF="Control-Monad-Instances.html#t%3AFunctor" >Functor</A ></TT > and <TT ><A HREF="Control-Monad-Instances.html#t%3AMonad" >Monad</A ></TT > instances for <TT >(->) r</TT > and <TT ><A HREF="Control-Monad-Instances.html#t%3AFunctor" >Functor</A ></TT > instances for <TT >(,) a</TT > and <TT ><TT ><A HREF="Data-Either.html#t%3AEither" >Either</A ></TT > a</TT >. </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" >class</SPAN > <A HREF="#t%3AFunctor" >Functor</A > f <SPAN CLASS="keyword" >where</SPAN ></TD ></TR ><TR ><TD CLASS="body" ><TABLE CLASS="vanilla" CELLSPACING="0" CELLPADDING="0" ><TR ><TD CLASS="decl" ><A HREF="#v%3Afmap" >fmap</A > :: (a -> b) -> f a -> f b</TD ></TR ></TABLE ></TD ></TR ><TR ><TD CLASS="s8" ></TD ></TR ><TR ><TD CLASS="decl" ><SPAN CLASS="keyword" >class</SPAN > <A HREF="#t%3AMonad" >Monad</A > m <SPAN CLASS="keyword" >where</SPAN ></TD ></TR ><TR ><TD CLASS="body" ><TABLE CLASS="vanilla" CELLSPACING="0" CELLPADDING="0" ><TR ><TD CLASS="decl" ><A HREF="#v%3A%3E%3E%3D" >(>>=)</A > :: <SPAN CLASS="keyword" >forall</SPAN > a b. m a -> (a -> m b) -> m b</TD ></TR ><TR ><TD CLASS="decl" ><A HREF="#v%3A%3E%3E" >(>>)</A > :: <SPAN CLASS="keyword" >forall</SPAN > a b. m a -> m b -> m b</TD ></TR ><TR ><TD CLASS="decl" ><A HREF="#v%3Areturn" >return</A > :: a -> m a</TD ></TR ><TR ><TD CLASS="decl" ><A HREF="#v%3Afail" >fail</A > :: <A HREF="Data-Char.html#t%3AString" >String</A > -> m 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" >class</SPAN > <A NAME="t:Functor" ><A NAME="t%3AFunctor" ></A ></A ><B >Functor</B > f <SPAN CLASS="keyword" >where</SPAN ></TD ></TR ><TR ><TD CLASS="body" ><TABLE CLASS="vanilla" CELLSPACING="0" CELLPADDING="0" ><TR ><TD CLASS="ndoc" ><P >The <TT ><A HREF="Control-Monad-Instances.html#t%3AFunctor" >Functor</A ></TT > class is used for types that can be mapped over. Instances of <TT ><A HREF="Control-Monad-Instances.html#t%3AFunctor" >Functor</A ></TT > should satisfy the following laws: </P ><PRE > fmap id == id fmap (f . g) == fmap f . fmap g </PRE ><P >The instances of <TT ><A HREF="Control-Monad-Instances.html#t%3AFunctor" >Functor</A ></TT > for lists, Data.Maybe.Maybe and System.IO.IO defined in the <A HREF="Prelude.html" >Prelude</A > satisfy these laws. </P ></TD ></TR ><TR ><TD CLASS="s8" ></TD ></TR ><TR ><TD CLASS="section4" >Methods</TD ></TR ><TR ><TD CLASS="body" ><TABLE CLASS="vanilla" CELLSPACING="0" CELLPADDING="0" ><TR ><TD CLASS="decl" ><A NAME="v:fmap" ><A NAME="v%3Afmap" ></A ></A ><B >fmap</B > :: (a -> b) -> f a -> f b</TD ></TR ></TABLE ></TD ></TR ><TR ><TD CLASS="s8" ></TD ></TR ><TR ><TD CLASS="section4" ><IMG SRC="minus.gif" CLASS="coll" ONCLICK="toggle(this,'i:Functor')" ALT="show/hide" > Instances</TD ></TR ><TR ><TD CLASS="body" ><DIV ID="i:Functor" STYLE="display:block;" ><TABLE CLASS="vanilla" CELLSPACING="1" CELLPADDING="0" ><TR ><TD CLASS="decl" ><A HREF="Control-Monad-Instances.html#t%3AFunctor" >Functor</A > []</TD ></TR ><TR ><TD CLASS="decl" ><A HREF="Control-Monad-Instances.html#t%3AFunctor" >Functor</A > <A HREF="System-IO.html#t%3AIO" >IO</A ></TD ></TR ><TR ><TD CLASS="decl" ><A HREF="Control-Monad-Instances.html#t%3AFunctor" >Functor</A > [::]</TD ></TR ><TR ><TD CLASS="decl" ><A HREF="Control-Monad-Instances.html#t%3AFunctor" >Functor</A > <A HREF="Data-Maybe.html#t%3AMaybe" >Maybe</A ></TD ></TR ><TR ><TD CLASS="decl" ><A HREF="Control-Monad-Instances.html#t%3AFunctor" >Functor</A > <A HREF="Text-ParserCombinators-ReadP.html#t%3AReadP" >ReadP</A ></TD ></TR ><TR ><TD CLASS="decl" ><A HREF="Control-Monad-Instances.html#t%3AFunctor" >Functor</A > <A HREF="Text-ParserCombinators-ReadPrec.html#t%3AReadPrec" >ReadPrec</A ></TD ></TR ><TR ><TD CLASS="decl" ><A HREF="Control-Monad-Instances.html#t%3AFunctor" >Functor</A > <A HREF="GHC-Conc.html#t%3ASTM" >STM</A ></TD ></TR ><TR ><TD CLASS="decl" ><A HREF="Control-Monad-Instances.html#t%3AFunctor" >Functor</A > <A HREF="Control-Applicative.html#t%3AZipList" >ZipList</A ></TD ></TR ><TR ><TD CLASS="decl" ><A HREF="Control-Monad-Instances.html#t%3AFunctor" >Functor</A > Id</TD ></TR ><TR ><TD CLASS="decl" ><A HREF="Control-Monad-Instances.html#t%3AFunctor" >Functor</A > ((->) r)</TD ></TR ><TR ><TD CLASS="decl" ><A HREF="Control-Monad-Instances.html#t%3AFunctor" >Functor</A > (<A HREF="Data-Either.html#t%3AEither" >Either</A > a)</TD ></TR ><TR ><TD CLASS="decl" ><A HREF="Control-Monad-Instances.html#t%3AFunctor" >Functor</A > (<A HREF="../ghc-prim/GHC-Tuple.html#t%3A%28%2C%29" >(,)</A > a)</TD ></TR ><TR ><TD CLASS="decl" ><A HREF="Control-Monad-Instances.html#t%3AFunctor" >Functor</A > (<A HREF="Control-Monad-ST.html#t%3AST" >ST</A > s)</TD ></TR ><TR ><TD CLASS="decl" ><A HREF="GHC-Arr.html#t%3AIx" >Ix</A > i => <A HREF="Control-Monad-Instances.html#t%3AFunctor" >Functor</A > (<A HREF="GHC-Arr.html#t%3AArray" >Array</A > i)</TD ></TR ><TR ><TD CLASS="decl" ><A HREF="Control-Monad-Instances.html#t%3AFunctor" >Functor</A > (<A HREF="Control-Monad-ST-Lazy.html#t%3AST" >ST</A > s)</TD ></TR ><TR ><TD CLASS="decl" ><A HREF="Control-Monad-Instances.html#t%3AMonad" >Monad</A > m => <A HREF="Control-Monad-Instances.html#t%3AFunctor" >Functor</A > (<A HREF="Control-Applicative.html#t%3AWrappedMonad" >WrappedMonad</A > m)</TD ></TR ><TR ><TD CLASS="decl" ><A HREF="Control-Monad-Instances.html#t%3AFunctor" >Functor</A > (<A HREF="Control-Applicative.html#t%3AConst" >Const</A > m)</TD ></TR ><TR ><TD CLASS="decl" ><A HREF="Control-Monad-Instances.html#t%3AFunctor" >Functor</A > (StateR s)</TD ></TR ><TR ><TD CLASS="decl" ><A HREF="Control-Monad-Instances.html#t%3AFunctor" >Functor</A > (StateL s)</TD ></TR ><TR ><TD CLASS="decl" ><A HREF="Control-Arrow.html#t%3AArrow" >Arrow</A > a => <A HREF="Control-Monad-Instances.html#t%3AFunctor" >Functor</A > (<A HREF="Control-Applicative.html#t%3AWrappedArrow" >WrappedArrow</A > a b)</TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE ></TD ></TR ><TR ><TD CLASS="s15" ></TD ></TR ><TR ><TD CLASS="decl" ><SPAN CLASS="keyword" >class</SPAN > <A NAME="t:Monad" ><A NAME="t%3AMonad" ></A ></A ><B >Monad</B > m <SPAN CLASS="keyword" >where</SPAN ></TD ></TR ><TR ><TD CLASS="body" ><TABLE CLASS="vanilla" CELLSPACING="0" CELLPADDING="0" ><TR ><TD CLASS="ndoc" ><P >The <TT ><A HREF="Control-Monad-Instances.html#t%3AMonad" >Monad</A ></TT > class defines the basic operations over a <EM >monad</EM >, a concept from a branch of mathematics known as <EM >category theory</EM >. From the perspective of a Haskell programmer, however, it is best to think of a monad as an <EM >abstract datatype</EM > of actions. Haskell's <TT >do</TT > expressions provide a convenient syntax for writing monadic expressions. </P ><P >Minimal complete definition: <TT ><A HREF="Control-Monad-Instances.html#v%3A%3E%3E%3D" >>>=</A ></TT > and <TT ><A HREF="Control-Monad-Instances.html#v%3Areturn" >return</A ></TT >. </P ><P >Instances of <TT ><A HREF="Control-Monad-Instances.html#t%3AMonad" >Monad</A ></TT > should satisfy the following laws: </P ><PRE > return a >>= k == k a m >>= return == m m >>= (\x -> k x >>= h) == (m >>= k) >>= h </PRE ><P >Instances of both <TT ><A HREF="Control-Monad-Instances.html#t%3AMonad" >Monad</A ></TT > and <TT ><A HREF="Control-Monad-Instances.html#t%3AFunctor" >Functor</A ></TT > should additionally satisfy the law: </P ><PRE > fmap f xs == xs >>= return . f </PRE ><P >The instances of <TT ><A HREF="Control-Monad-Instances.html#t%3AMonad" >Monad</A ></TT > for lists, Data.Maybe.Maybe and System.IO.IO defined in the <A HREF="Prelude.html" >Prelude</A > satisfy these laws. </P ></TD ></TR ><TR ><TD CLASS="s8" ></TD ></TR ><TR ><TD CLASS="section4" >Methods</TD ></TR ><TR ><TD CLASS="body" ><TABLE CLASS="vanilla" CELLSPACING="0" CELLPADDING="0" ><TR ><TD CLASS="decl" ><A NAME="v:>>=" ><A NAME="v%3A%3E%3E%3D" ></A ></A ><B >(>>=)</B > :: <SPAN CLASS="keyword" >forall</SPAN > a b. m a -> (a -> m b) -> m b</TD ></TR ><TR ><TD CLASS="doc" >Sequentially compose two actions, passing any value produced by the first as an argument to the second. </TD ></TR ><TR ><TD CLASS="s8" ></TD ></TR ><TR ><TD CLASS="decl" ><A NAME="v:>>" ><A NAME="v%3A%3E%3E" ></A ></A ><B >(>>)</B > :: <SPAN CLASS="keyword" >forall</SPAN > a b. m a -> m b -> m b</TD ></TR ><TR ><TD CLASS="doc" >Sequentially compose two actions, discarding any value produced by the first, like sequencing operators (such as the semicolon) in imperative languages. </TD ></TR ><TR ><TD CLASS="s8" ></TD ></TR ><TR ><TD CLASS="decl" ><A NAME="v:return" ><A NAME="v%3Areturn" ></A ></A ><B >return</B > :: a -> m a</TD ></TR ><TR ><TD CLASS="doc" >Inject a value into the monadic type. </TD ></TR ><TR ><TD CLASS="s8" ></TD ></TR ><TR ><TD CLASS="decl" ><A NAME="v:fail" ><A NAME="v%3Afail" ></A ></A ><B >fail</B > :: <A HREF="Data-Char.html#t%3AString" >String</A > -> m a</TD ></TR ><TR ><TD CLASS="doc" >Fail with a message. This operation is not part of the mathematical definition of a monad, but is invoked on pattern-match failure in a <TT >do</TT > expression. </TD ></TR ></TABLE ></TD ></TR ><TR ><TD CLASS="s8" ></TD ></TR ><TR ><TD CLASS="section4" ><IMG SRC="minus.gif" CLASS="coll" ONCLICK="toggle(this,'i:Monad')" ALT="show/hide" > Instances</TD ></TR ><TR ><TD CLASS="body" ><DIV ID="i:Monad" STYLE="display:block;" ><TABLE CLASS="vanilla" CELLSPACING="1" CELLPADDING="0" ><TR ><TD CLASS="decl" ><A HREF="Control-Monad-Instances.html#t%3AMonad" >Monad</A > []</TD ></TR ><TR ><TD CLASS="decl" ><A HREF="Control-Monad-Instances.html#t%3AMonad" >Monad</A > <A HREF="System-IO.html#t%3AIO" >IO</A ></TD ></TR ><TR ><TD CLASS="decl" ><A HREF="Control-Monad-Instances.html#t%3AMonad" >Monad</A > [::]</TD ></TR ><TR ><TD CLASS="decl" ><A HREF="Control-Monad-Instances.html#t%3AMonad" >Monad</A > <A HREF="Data-Maybe.html#t%3AMaybe" >Maybe</A ></TD ></TR ><TR ><TD CLASS="decl" ><A HREF="Control-Monad-Instances.html#t%3AMonad" >Monad</A > <A HREF="Text-ParserCombinators-ReadP.html#t%3AReadP" >ReadP</A ></TD ></TR ><TR ><TD CLASS="decl" ><A HREF="Control-Monad-Instances.html#t%3AMonad" >Monad</A > P</TD ></TR ><TR ><TD CLASS="decl" ><A HREF="Control-Monad-Instances.html#t%3AMonad" >Monad</A > <A HREF="Text-ParserCombinators-ReadPrec.html#t%3AReadPrec" >ReadPrec</A ></TD ></TR ><TR ><TD CLASS="decl" ><A HREF="Control-Monad-Instances.html#t%3AMonad" >Monad</A > <A HREF="GHC-Conc.html#t%3ASTM" >STM</A ></TD ></TR ><TR ><TD CLASS="decl" ><A HREF="Control-Monad-Instances.html#t%3AMonad" >Monad</A > ((->) r)</TD ></TR ><TR ><TD CLASS="decl" ><A HREF="Control-Monad-Instances.html#t%3AMonad" >Monad</A > (<A HREF="Control-Monad-ST.html#t%3AST" >ST</A > s)</TD ></TR ><TR ><TD CLASS="decl" ><A HREF="Control-Arrow.html#t%3AArrowApply" >ArrowApply</A > a => <A HREF="Control-Monad-Instances.html#t%3AMonad" >Monad</A > (<A HREF="Control-Arrow.html#t%3AArrowMonad" >ArrowMonad</A > a)</TD ></TR ><TR ><TD CLASS="decl" ><A HREF="Control-Monad-Instances.html#t%3AMonad" >Monad</A > (<A HREF="Control-Monad-ST-Lazy.html#t%3AST" >ST</A > s)</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 2.4.2</TD ></TR ></TABLE ></BODY ></HTML >