Note that there are some explanatory texts on larger screens.

plurals
  1. PODo Traversables really require to be traversed "left-to-right"?
    text
    copied!<p>I have an infinite structure like the following (using the <a href="http://hackage.haskell.org/packages/archive/streams/3.0/doc/html/Data-Stream-Infinite.html">Stream</a> type from the <a href="http://hackage.haskell.org/package/streams">streams</a> package):</p> <pre><code>data U x = U (Stream x) x (Stream x) deriving (Functor,Foldable) </code></pre> <p>I want to provide an instance of Traversable for it, like this:</p> <pre><code>instance Traversable U where traverse f (U lstream focus rstream) = let pairs = liftA unzip . sequenceA . fmap (traversepair f) $ zip lstream rstream traversepair f (a,b) = (,) &lt;$&gt; f a &lt;*&gt; f b rebuild c (u,v) = U u c v in rebuild &lt;$&gt; f focus &lt;*&gt; pairs </code></pre> <p>The <a href="http://www.haskell.org/ghc/docs/latest/html/libraries/base/Data-Traversable.html">documentation for Data.Traversable</a> says that they represent the "class of data structures that can be traversed from left to right". But my definition does not traverse from left to right, it traverses <em>outwardly</em>. I had to define it that way to be able to lazily extract values on both sides after a <a href="http://www.haskell.org/ghc/docs/latest/html/libraries/base/Data-Traversable.html#v%3asequence">sequence</a> operation involving the <a href="http://hackage.haskell.org/packages/archive/MonadRandom/0.1.8/doc/html/Control-Monad-Random.html#t%3aRand">Rand</a> monad.</p> <p>Is it a valid definition nonetheless? I have noticed that the <a href="http://www.haskell.org/haskellwiki/Typeclassopedia#Traversable">Typeclassopedia entry for Traversable</a> doesn't say anything about "left-to-right", it only talks about "commuting two functors".</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload