Sophie

Sophie

distrib > Fedora > 14 > x86_64 > media > updates > by-pkgid > 77f0c8b2568c8ba86bf4498d38e7ecdc > files > 770

ghc-base-devel-4.2.0.2-8.6.fc14.x86_64.rpm

<!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
>Data.Traversable</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_Data-Traversable.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.2.0.2: 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"
>Data.Traversable</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 CLASS="section1"
>Description</TD
></TR
><TR
><TD CLASS="doc"
><P
>Class of data structures that can be traversed from left to right,
 performing an action on each element.
</P
><P
>See also
</P
><UL
><LI
> <EM
>Applicative Programming with Effects</EM
>,
    by Conor McBride and Ross Paterson, online at
    <A HREF="http://www.soi.city.ac.uk/~ross/papers/Applicative.html"
>http://www.soi.city.ac.uk/~ross/papers/Applicative.html</A
>.
</LI
><LI
> <EM
>The Essence of the Iterator Pattern</EM
>,
    by Jeremy Gibbons and Bruno Oliveira,
    in <EM
>Mathematically-Structured Functional Programming</EM
>, 2006, and online at
    <A HREF="http://web.comlab.ox.ac.uk/oucl/work/jeremy.gibbons/publications/#iterator"
>http://web.comlab.ox.ac.uk/oucl/work/jeremy.gibbons/publications/#iterator</A
>.
</LI
></UL
><P
>Note that the functions <TT
><A HREF="Data-Traversable.html#v%3AmapM"
>mapM</A
></TT
> and <TT
><A HREF="Data-Traversable.html#v%3Asequence"
>sequence</A
></TT
> generalize <A HREF="Prelude.html"
>Prelude</A
>
 functions of the same names from lists to any <TT
><A HREF="Data-Traversable.html#t%3ATraversable"
>Traversable</A
></TT
> functor.
 To avoid ambiguity, either import the <A HREF="Prelude.html"
>Prelude</A
> hiding these names
 or qualify uses of these function names with an alias for this module.
</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"
>class</SPAN
> (<A HREF="Control-Monad.html#t%3AFunctor"
>Functor</A
> t, <A HREF="Data-Foldable.html#t%3AFoldable"
>Foldable</A
> t) =&gt; <A HREF="#t%3ATraversable"
>Traversable</A
> t  <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%3Atraverse"
>traverse</A
> :: <A HREF="Control-Applicative.html#t%3AApplicative"
>Applicative</A
> f =&gt; (a -&gt; f b) -&gt; t a -&gt; f (t b)</TD
></TR
><TR
><TD CLASS="decl"
><A HREF="#v%3AsequenceA"
>sequenceA</A
> :: <A HREF="Control-Applicative.html#t%3AApplicative"
>Applicative</A
> f =&gt; t (f a) -&gt; f (t a)</TD
></TR
><TR
><TD CLASS="decl"
><A HREF="#v%3AmapM"
>mapM</A
> :: <A HREF="Control-Monad.html#t%3AMonad"
>Monad</A
> m =&gt; (a -&gt; m b) -&gt; t a -&gt; m (t b)</TD
></TR
><TR
><TD CLASS="decl"
><A HREF="#v%3Asequence"
>sequence</A
> :: <A HREF="Control-Monad.html#t%3AMonad"
>Monad</A
> m =&gt; t (m a) -&gt; m (t a)</TD
></TR
></TABLE
></TD
></TR
><TR
><TD CLASS="s8"
></TD
></TR
><TR
><TD CLASS="decl"
><A HREF="#v%3Afor"
>for</A
> :: (<A HREF="Data-Traversable.html#t%3ATraversable"
>Traversable</A
> t, <A HREF="Control-Applicative.html#t%3AApplicative"
>Applicative</A
> f) =&gt; t a -&gt; (a -&gt; f b) -&gt; f (t b)</TD
></TR
><TR
><TD CLASS="s8"
></TD
></TR
><TR
><TD CLASS="decl"
><A HREF="#v%3AforM"
>forM</A
> :: (<A HREF="Data-Traversable.html#t%3ATraversable"
>Traversable</A
> t, <A HREF="Control-Monad.html#t%3AMonad"
>Monad</A
> m) =&gt; t a -&gt; (a -&gt; m b) -&gt; m (t b)</TD
></TR
><TR
><TD CLASS="s8"
></TD
></TR
><TR
><TD CLASS="decl"
><A HREF="#v%3AmapAccumL"
>mapAccumL</A
> :: <A HREF="Data-Traversable.html#t%3ATraversable"
>Traversable</A
> t =&gt; (a -&gt; b -&gt; (a, c)) -&gt; a -&gt; t b -&gt; (a, t c)</TD
></TR
><TR
><TD CLASS="s8"
></TD
></TR
><TR
><TD CLASS="decl"
><A HREF="#v%3AmapAccumR"
>mapAccumR</A
> :: <A HREF="Data-Traversable.html#t%3ATraversable"
>Traversable</A
> t =&gt; (a -&gt; b -&gt; (a, c)) -&gt; a -&gt; t b -&gt; (a, t c)</TD
></TR
><TR
><TD CLASS="s8"
></TD
></TR
><TR
><TD CLASS="decl"
><A HREF="#v%3AfmapDefault"
>fmapDefault</A
> :: <A HREF="Data-Traversable.html#t%3ATraversable"
>Traversable</A
> t =&gt; (a -&gt; b) -&gt; t a -&gt; t b</TD
></TR
><TR
><TD CLASS="s8"
></TD
></TR
><TR
><TD CLASS="decl"
><A HREF="#v%3AfoldMapDefault"
>foldMapDefault</A
> :: (<A HREF="Data-Traversable.html#t%3ATraversable"
>Traversable</A
> t, <A HREF="Data-Monoid.html#t%3AMonoid"
>Monoid</A
> m) =&gt; (a -&gt; m) -&gt; t a -&gt; m</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 HREF="Control-Monad.html#t%3AFunctor"
>Functor</A
> t, <A HREF="Data-Foldable.html#t%3AFoldable"
>Foldable</A
> t) =&gt; <A NAME="t:Traversable"
><A NAME="t%3ATraversable"
></A
></A
><B
>Traversable</B
> t  <SPAN CLASS="keyword"
>where</SPAN
></TD
></TR
><TR
><TD CLASS="body"
><TABLE CLASS="vanilla" CELLSPACING="0" CELLPADDING="0"
><TR
><TD CLASS="ndoc"
><P
>Functors representing data structures that can be traversed from
 left to right.
</P
><P
>Minimal complete definition: <TT
><A HREF="Data-Traversable.html#v%3Atraverse"
>traverse</A
></TT
> or <TT
><A HREF="Data-Traversable.html#v%3AsequenceA"
>sequenceA</A
></TT
>.
</P
><P
>Instances are similar to <TT
><A HREF="Control-Monad.html#t%3AFunctor"
>Functor</A
></TT
>, e.g. given a data type
</P
><PRE
> data Tree a = Empty | Leaf a | Node (Tree a) a (Tree a)
</PRE
><P
>a suitable instance would be
</P
><PRE
> instance Traversable Tree
    traverse f Empty = pure Empty
    traverse f (Leaf x) = Leaf &lt;$&gt; f x
    traverse f (Node l k r) = Node &lt;$&gt; traverse f l &lt;*&gt; f k &lt;*&gt; traverse f r
</PRE
><P
>This is suitable even for abstract types, as the laws for <TT
><A HREF="Control-Applicative.html#v%3A%3C%2A%3E"
>&lt;*&gt;</A
></TT
>
 imply a form of associativity.
</P
><P
>The superclass instances should satisfy the following:
</P
><UL
><LI
> In the <TT
><A HREF="Control-Monad.html#t%3AFunctor"
>Functor</A
></TT
> instance, <TT
><A HREF="Control-Monad.html#v%3Afmap"
>fmap</A
></TT
> should be equivalent to traversal
    with the identity applicative functor (<TT
><A HREF="Data-Traversable.html#v%3AfmapDefault"
>fmapDefault</A
></TT
>).
</LI
><LI
> In the <TT
><A HREF="Data-Foldable.html#t%3AFoldable"
>Foldable</A
></TT
> instance, Data.Foldable.foldMap should be
    equivalent to traversal with a constant applicative functor
    (<TT
><A HREF="Data-Traversable.html#v%3AfoldMapDefault"
>foldMapDefault</A
></TT
>).
</LI
></UL
></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:traverse"
><A NAME="v%3Atraverse"
></A
></A
><B
>traverse</B
> :: <A HREF="Control-Applicative.html#t%3AApplicative"
>Applicative</A
> f =&gt; (a -&gt; f b) -&gt; t a -&gt; f (t b)</TD
></TR
><TR
><TD CLASS="doc"
>Map each element of a structure to an action, evaluate
 these actions from left to right, and collect the results.
</TD
></TR
><TR
><TD CLASS="s8"
></TD
></TR
><TR
><TD CLASS="decl"
><A NAME="v:sequenceA"
><A NAME="v%3AsequenceA"
></A
></A
><B
>sequenceA</B
> :: <A HREF="Control-Applicative.html#t%3AApplicative"
>Applicative</A
> f =&gt; t (f a) -&gt; f (t a)</TD
></TR
><TR
><TD CLASS="doc"
>Evaluate each action in the structure from left to right,
 and collect the results.
</TD
></TR
><TR
><TD CLASS="s8"
></TD
></TR
><TR
><TD CLASS="decl"
><A NAME="v:mapM"
><A NAME="v%3AmapM"
></A
></A
><B
>mapM</B
> :: <A HREF="Control-Monad.html#t%3AMonad"
>Monad</A
> m =&gt; (a -&gt; m b) -&gt; t a -&gt; m (t b)</TD
></TR
><TR
><TD CLASS="doc"
>Map each element of a structure to a monadic action, evaluate
 these actions from left to right, and collect the results.
</TD
></TR
><TR
><TD CLASS="s8"
></TD
></TR
><TR
><TD CLASS="decl"
><A NAME="v:sequence"
><A NAME="v%3Asequence"
></A
></A
><B
>sequence</B
> :: <A HREF="Control-Monad.html#t%3AMonad"
>Monad</A
> m =&gt; t (m a) -&gt; m (t a)</TD
></TR
><TR
><TD CLASS="doc"
>Evaluate each monadic action in the structure from left to right,
 and collect the results.
</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:Traversable')" ALT="show/hide"
> Instances</TD
></TR
><TR
><TD CLASS="body"
><DIV ID="i:Traversable" STYLE="display:block;"
><TABLE CLASS="vanilla" CELLSPACING="1" CELLPADDING="0"
><TR
><TD CLASS="decl"
><A HREF="Data-Traversable.html#t%3ATraversable"
>Traversable</A
> []</TD
></TR
><TR
><TD CLASS="decl"
><A HREF="Data-Traversable.html#t%3ATraversable"
>Traversable</A
> <A HREF="Data-Maybe.html#t%3AMaybe"
>Maybe</A
></TD
></TR
><TR
><TD CLASS="decl"
><A HREF="Data-Ix.html#t%3AIx"
>Ix</A
> i =&gt; <A HREF="Data-Traversable.html#t%3ATraversable"
>Traversable</A
> (Array i)</TD
></TR
></TABLE
></DIV
></TD
></TR
></TABLE
></TD
></TR
><TR
><TD CLASS="s15"
></TD
></TR
><TR
><TD CLASS="decl"
><A NAME="v:for"
><A NAME="v%3Afor"
></A
></A
><B
>for</B
> :: (<A HREF="Data-Traversable.html#t%3ATraversable"
>Traversable</A
> t, <A HREF="Control-Applicative.html#t%3AApplicative"
>Applicative</A
> f) =&gt; t a -&gt; (a -&gt; f b) -&gt; f (t b)</TD
></TR
><TR
><TD CLASS="doc"
><TT
><A HREF="Data-Traversable.html#v%3Afor"
>for</A
></TT
> is <TT
><A HREF="Data-Traversable.html#v%3Atraverse"
>traverse</A
></TT
> with its arguments flipped.
</TD
></TR
><TR
><TD CLASS="s15"
></TD
></TR
><TR
><TD CLASS="decl"
><A NAME="v:forM"
><A NAME="v%3AforM"
></A
></A
><B
>forM</B
> :: (<A HREF="Data-Traversable.html#t%3ATraversable"
>Traversable</A
> t, <A HREF="Control-Monad.html#t%3AMonad"
>Monad</A
> m) =&gt; t a -&gt; (a -&gt; m b) -&gt; m (t b)</TD
></TR
><TR
><TD CLASS="doc"
><TT
><A HREF="Data-Traversable.html#v%3AforM"
>forM</A
></TT
> is <TT
><A HREF="Data-Traversable.html#v%3AmapM"
>mapM</A
></TT
> with its arguments flipped.
</TD
></TR
><TR
><TD CLASS="s15"
></TD
></TR
><TR
><TD CLASS="decl"
><A NAME="v:mapAccumL"
><A NAME="v%3AmapAccumL"
></A
></A
><B
>mapAccumL</B
> :: <A HREF="Data-Traversable.html#t%3ATraversable"
>Traversable</A
> t =&gt; (a -&gt; b -&gt; (a, c)) -&gt; a -&gt; t b -&gt; (a, t c)</TD
></TR
><TR
><TD CLASS="doc"
>The <TT
><A HREF="Data-Traversable.html#v%3AmapAccumL"
>mapAccumL</A
></TT
> function behaves like a combination of <TT
><A HREF="Control-Monad.html#v%3Afmap"
>fmap</A
></TT
>
 and <TT
><A HREF="Data-List.html#v%3Afoldl"
>foldl</A
></TT
>; it applies a function to each element of a structure,
 passing an accumulating parameter from left to right, and returning
 a final value of this accumulator together with the new structure.
</TD
></TR
><TR
><TD CLASS="s15"
></TD
></TR
><TR
><TD CLASS="decl"
><A NAME="v:mapAccumR"
><A NAME="v%3AmapAccumR"
></A
></A
><B
>mapAccumR</B
> :: <A HREF="Data-Traversable.html#t%3ATraversable"
>Traversable</A
> t =&gt; (a -&gt; b -&gt; (a, c)) -&gt; a -&gt; t b -&gt; (a, t c)</TD
></TR
><TR
><TD CLASS="doc"
>The <TT
><A HREF="Data-Traversable.html#v%3AmapAccumR"
>mapAccumR</A
></TT
> function behaves like a combination of <TT
><A HREF="Control-Monad.html#v%3Afmap"
>fmap</A
></TT
>
 and foldr; it applies a function to each element of a structure,
 passing an accumulating parameter from right to left, and returning
 a final value of this accumulator together with the new structure.
</TD
></TR
><TR
><TD CLASS="s15"
></TD
></TR
><TR
><TD CLASS="decl"
><A NAME="v:fmapDefault"
><A NAME="v%3AfmapDefault"
></A
></A
><B
>fmapDefault</B
> :: <A HREF="Data-Traversable.html#t%3ATraversable"
>Traversable</A
> t =&gt; (a -&gt; b) -&gt; t a -&gt; t b</TD
></TR
><TR
><TD CLASS="doc"
>This function may be used as a value for <TT
><A HREF="Control-Monad.html#v%3Afmap"
>fmap</A
></TT
> in a <TT
><A HREF="Control-Monad.html#t%3AFunctor"
>Functor</A
></TT
> instance.
</TD
></TR
><TR
><TD CLASS="s15"
></TD
></TR
><TR
><TD CLASS="decl"
><A NAME="v:foldMapDefault"
><A NAME="v%3AfoldMapDefault"
></A
></A
><B
>foldMapDefault</B
> :: (<A HREF="Data-Traversable.html#t%3ATraversable"
>Traversable</A
> t, <A HREF="Data-Monoid.html#t%3AMonoid"
>Monoid</A
> m) =&gt; (a -&gt; m) -&gt; t a -&gt; m</TD
></TR
><TR
><TD CLASS="doc"
>This function may be used as a value for Data.Foldable.foldMap
 in a <TT
><A HREF="Data-Foldable.html#t%3AFoldable"
>Foldable</A
></TT
> instance.
</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.6.1</TD
></TR
></TABLE
></BODY
></HTML
>