Sophie

Sophie

distrib > Mageia > 5 > i586 > media > core-release > by-pkgid > 6e204a966e8c42d976f99a1700ce5f20 > files > 2260

ghc-7.4.2-4.mga5.i586.rpm

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>Data.Traversable</title><link href="ocean.css" rel="stylesheet" type="text/css" title="Ocean" /><script src="haddock-util.js" type="text/javascript"></script><script type="text/javascript">//<![CDATA[
window.onload = function () {pageLoad();setSynopsis("mini_Data-Traversable.html");};
//]]>
</script></head><body><div id="package-header"><ul class="links" id="page-menu"><li><a href="index.html">Contents</a></li><li><a href="doc-index.html">Index</a></li></ul><p class="caption">base-4.5.1.0: Basic libraries</p></div><div id="content"><div id="module-header"><table class="info"><tr><th>Portability</th><td>portable</td></tr><tr><th>Stability</th><td>experimental</td></tr><tr><th>Maintainer</th><td>libraries@haskell.org</td></tr><tr><th>Safe Haskell</th><td>Trustworthy</td></tr></table><p class="caption">Data.Traversable</p></div><div id="description"><p class="caption">Description</p><div 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 <code><a href="Data-Traversable.html#v:mapM">mapM</a></code> and <code><a href="Data-Traversable.html#v:sequence">sequence</a></code> generalize <a href="Prelude.html">Prelude</a>
 functions of the same names from lists to any <code><a href="Data-Traversable.html#t:Traversable">Traversable</a></code> 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></div></div><div id="synopsis"><p id="control.syn" class="caption expander" onclick="toggleSection('syn')">Synopsis</p><ul id="section.syn" class="hide" onclick="toggleSection('syn')"><li class="src short"><span class="keyword">class</span> (<a href="Control-Monad.html#t:Functor">Functor</a> t, <a href="Data-Foldable.html#t:Foldable">Foldable</a> t) =&gt; <a href="#t:Traversable">Traversable</a> t  <span class="keyword">where</span><ul class="subs"><li><a href="#v:traverse">traverse</a> :: <a href="Control-Applicative.html#t:Applicative">Applicative</a> f =&gt; (a -&gt; f b) -&gt; t a -&gt; f (t b)</li><li><a href="#v:sequenceA">sequenceA</a> :: <a href="Control-Applicative.html#t:Applicative">Applicative</a> f =&gt; t (f a) -&gt; f (t a)</li><li><a href="#v:mapM">mapM</a> :: <a href="Control-Monad.html#t:Monad">Monad</a> m =&gt; (a -&gt; m b) -&gt; t a -&gt; m (t b)</li><li><a href="#v:sequence">sequence</a> :: <a href="Control-Monad.html#t:Monad">Monad</a> m =&gt; t (m a) -&gt; m (t a)</li></ul></li><li class="src short"><a href="#v:for">for</a> :: (<a href="Data-Traversable.html#t:Traversable">Traversable</a> t, <a href="Control-Applicative.html#t:Applicative">Applicative</a> f) =&gt; t a -&gt; (a -&gt; f b) -&gt; f (t b)</li><li class="src short"><a href="#v:forM">forM</a> :: (<a href="Data-Traversable.html#t:Traversable">Traversable</a> t, <a href="Control-Monad.html#t:Monad">Monad</a> m) =&gt; t a -&gt; (a -&gt; m b) -&gt; m (t b)</li><li class="src short"><a href="#v:mapAccumL">mapAccumL</a> :: <a href="Data-Traversable.html#t:Traversable">Traversable</a> t =&gt; (a -&gt; b -&gt; (a, c)) -&gt; a -&gt; t b -&gt; (a, t c)</li><li class="src short"><a href="#v:mapAccumR">mapAccumR</a> :: <a href="Data-Traversable.html#t:Traversable">Traversable</a> t =&gt; (a -&gt; b -&gt; (a, c)) -&gt; a -&gt; t b -&gt; (a, t c)</li><li class="src short"><a href="#v:fmapDefault">fmapDefault</a> :: <a href="Data-Traversable.html#t:Traversable">Traversable</a> t =&gt; (a -&gt; b) -&gt; t a -&gt; t b</li><li class="src short"><a href="#v:foldMapDefault">foldMapDefault</a> :: (<a href="Data-Traversable.html#t:Traversable">Traversable</a> t, <a href="Data-Monoid.html#t:Monoid">Monoid</a> m) =&gt; (a -&gt; m) -&gt; t a -&gt; m</li></ul></div><div id="interface"><h1>Documentation</h1><div class="top"><p class="src"><span class="keyword">class</span> (<a href="Control-Monad.html#t:Functor">Functor</a> t, <a href="Data-Foldable.html#t:Foldable">Foldable</a> t) =&gt; <a name="t:Traversable" class="def">Traversable</a> t  <span class="keyword">where</span></p><div class="doc"><p>Functors representing data structures that can be traversed from
 left to right.
</p><p>Minimal complete definition: <code><a href="Data-Traversable.html#v:traverse">traverse</a></code> or <code><a href="Data-Traversable.html#v:sequenceA">sequenceA</a></code>.
</p><p>Instances are similar to <code><a href="Control-Monad.html#t:Functor">Functor</a></code>, 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 where
    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 <code><a href="Control-Applicative.html#v:-60--42--62-">&lt;*&gt;</a></code>
 imply a form of associativity.
</p><p>The superclass instances should satisfy the following:
</p><ul><li> In the <code><a href="Control-Monad.html#t:Functor">Functor</a></code> instance, <code><a href="Control-Monad.html#v:fmap">fmap</a></code> should be equivalent to traversal
    with the identity applicative functor (<code><a href="Data-Traversable.html#v:fmapDefault">fmapDefault</a></code>).
</li><li> In the <code><a href="Data-Foldable.html#t:Foldable">Foldable</a></code> instance, <code><a href="Data-Foldable.html#v:foldMap">foldMap</a></code> should be
    equivalent to traversal with a constant applicative functor
    (<code><a href="Data-Traversable.html#v:foldMapDefault">foldMapDefault</a></code>).
</li></ul></div><div class="subs methods"><p class="caption">Methods</p><p class="src"><a name="v:traverse" class="def">traverse</a> :: <a href="Control-Applicative.html#t:Applicative">Applicative</a> f =&gt; (a -&gt; f b) -&gt; t a -&gt; f (t b)</p><div class="doc"><p>Map each element of a structure to an action, evaluate
 these actions from left to right, and collect the results.
</p></div><p class="src"><a name="v:sequenceA" class="def">sequenceA</a> :: <a href="Control-Applicative.html#t:Applicative">Applicative</a> f =&gt; t (f a) -&gt; f (t a)</p><div class="doc"><p>Evaluate each action in the structure from left to right,
 and collect the results.
</p></div><p class="src"><a name="v:mapM" class="def">mapM</a> :: <a href="Control-Monad.html#t:Monad">Monad</a> m =&gt; (a -&gt; m b) -&gt; t a -&gt; m (t b)</p><div class="doc"><p>Map each element of a structure to a monadic action, evaluate
 these actions from left to right, and collect the results.
</p></div><p class="src"><a name="v:sequence" class="def">sequence</a> :: <a href="Control-Monad.html#t:Monad">Monad</a> m =&gt; t (m a) -&gt; m (t a)</p><div class="doc"><p>Evaluate each monadic action in the structure from left to right,
 and collect the results.
</p></div></div><div class="subs instances"><p id="control.i:Traversable" class="caption collapser" onclick="toggleSection('i:Traversable')">Instances</p><div id="section.i:Traversable" class="show"><table><tr><td class="src"><a href="Data-Traversable.html#t:Traversable">Traversable</a> []</td><td class="doc empty">&nbsp;</td></tr><tr><td class="src"><a href="Data-Traversable.html#t:Traversable">Traversable</a> <a href="Data-Maybe.html#t:Maybe">Maybe</a></td><td class="doc empty">&nbsp;</td></tr><tr><td class="src"><a href="Data-Ix.html#t:Ix">Ix</a> i =&gt; <a href="Data-Traversable.html#t:Traversable">Traversable</a> (Array i)</td><td class="doc empty">&nbsp;</td></tr></table></div></div></div><div class="top"><p class="src"><a name="v:for" class="def">for</a> :: (<a href="Data-Traversable.html#t:Traversable">Traversable</a> t, <a href="Control-Applicative.html#t:Applicative">Applicative</a> f) =&gt; t a -&gt; (a -&gt; f b) -&gt; f (t b)</p><div class="doc"><p><code><a href="Data-Traversable.html#v:for">for</a></code> is <code><a href="Data-Traversable.html#v:traverse">traverse</a></code> with its arguments flipped.
</p></div></div><div class="top"><p class="src"><a name="v:forM" class="def">forM</a> :: (<a href="Data-Traversable.html#t:Traversable">Traversable</a> t, <a href="Control-Monad.html#t:Monad">Monad</a> m) =&gt; t a -&gt; (a -&gt; m b) -&gt; m (t b)</p><div class="doc"><p><code><a href="Data-Traversable.html#v:forM">forM</a></code> is <code><a href="Data-Traversable.html#v:mapM">mapM</a></code> with its arguments flipped.
</p></div></div><div class="top"><p class="src"><a name="v:mapAccumL" class="def">mapAccumL</a> :: <a href="Data-Traversable.html#t:Traversable">Traversable</a> t =&gt; (a -&gt; b -&gt; (a, c)) -&gt; a -&gt; t b -&gt; (a, t c)</p><div class="doc"><p>The <code><a href="Data-Traversable.html#v:mapAccumL">mapAccumL</a></code> function behaves like a combination of <code><a href="Control-Monad.html#v:fmap">fmap</a></code>
 and <code><a href="Data-List.html#v:foldl">foldl</a></code>; 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.
</p></div></div><div class="top"><p class="src"><a name="v:mapAccumR" class="def">mapAccumR</a> :: <a href="Data-Traversable.html#t:Traversable">Traversable</a> t =&gt; (a -&gt; b -&gt; (a, c)) -&gt; a -&gt; t b -&gt; (a, t c)</p><div class="doc"><p>The <code><a href="Data-Traversable.html#v:mapAccumR">mapAccumR</a></code> function behaves like a combination of <code><a href="Control-Monad.html#v:fmap">fmap</a></code>
 and <code>foldr</code>; 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.
</p></div></div><div class="top"><p class="src"><a name="v:fmapDefault" class="def">fmapDefault</a> :: <a href="Data-Traversable.html#t:Traversable">Traversable</a> t =&gt; (a -&gt; b) -&gt; t a -&gt; t b</p><div class="doc"><p>This function may be used as a value for <code><a href="Control-Monad.html#v:fmap">fmap</a></code> in a <code><a href="Control-Monad.html#t:Functor">Functor</a></code>
   instance, provided that <code><a href="Data-Traversable.html#v:traverse">traverse</a></code> is defined. (Using
   <code><a href="Data-Traversable.html#v:fmapDefault">fmapDefault</a></code> with a <code><a href="Data-Traversable.html#t:Traversable">Traversable</a></code> instance defined only by
   <code><a href="Data-Traversable.html#v:sequenceA">sequenceA</a></code> will result in infinite recursion.)
</p></div></div><div class="top"><p class="src"><a name="v:foldMapDefault" class="def">foldMapDefault</a> :: (<a href="Data-Traversable.html#t:Traversable">Traversable</a> t, <a href="Data-Monoid.html#t:Monoid">Monoid</a> m) =&gt; (a -&gt; m) -&gt; t a -&gt; m</p><div class="doc"><p>This function may be used as a value for <code><a href="Data-Foldable.html#v:foldMap">foldMap</a></code>
 in a <code><a href="Data-Foldable.html#t:Foldable">Foldable</a></code> instance.
</p></div></div></div></div><div id="footer"><p>Produced by <a href="http://www.haskell.org/haddock/">Haddock</a> version 2.11.0</p></div></body></html>