<br>First, let&#39;s lay out our definitions:<br><br>
unzip [] = ([], [])<br>
unzip ((x,y):xys) = (x:xs, y:ys) where (xs,ys) = unzip xys<br>
<br>
zip [] _ = []<br>
zip _ [] = []<br>
zip (x:xs) (y:ys) = (x,y) : zip xs ys<br><br>map _ [] = []<br>map f (x:xs) = f x : map f xs<br>
<br>stream ~(a:as) = a : stream as<br>
-- equivalently<br>
stream xs = head xs : stream (tail xs)<br>
<br>Now we want to evaluate this:<br>runSF (loop (arr swap))  [1,2,3]<br>
<br>Lets simplify some of the insides a bit:<br>arr swap<br>  = SF $ map swap<br>  = SF $ map (\(x,y)-&gt;(y,x))<br><br>loop (arr swap)<br>  = SF $ \as -&gt;<br>        let (bs,cs) = unzip (map swap (zip as (stream cs))) in bs<br>
<br>runSF (loop (arr swap))  [1,2,3]<br>  = runSF (SF $ ...) [1,2,3]<br>  = (\as -&gt; let (bs,cs) = unzip (map swap (zip as (stream cs))) in bs) [1,2,3]<br><br>Here is our heap at this point; we are trying to evaluate bs:<br>
<br>p = unzip (map swap (zip as (stream cs)))<br>as = [1,2,3]<br>bs = fst p<br>cs = snd p<br><br>snd p forces p, unzip forces its argument, map forces its second argument, and zip forces both its arguments.<br>So now we have:<br>
<br>p = unzip retmap<br>retmap = map swap retzip<br>retzip = zip as retstream<br>retstream = stream cs<br>as = [1,2,3]<br>bs = fst p<br>cs = snd p<br><br>Evaluating further:<br>retstream = head cs : retstream2<br>retstream2 = stream (tail cs)<br>
retzip = (1, head cs) : retzip2<br>retzip2 = zip [2,3] (stream (tail cs))<br>retmap = (head cs, 1) : retmap2<br>retmap2 = map swap retzip2<br>p = (head cs : xs1, 1 : ys1)<br>(xs1,ys1) = unzip retmap2<br>
bs = head cs : xs1<br>
cs = 1 : ys1<br>bs = 1 : xs1<br><br>and we can now return the first cons cell of bs.<br><br>This repeats until we get [1,2,3] back out; note that each value goes through both sides of the swap before coming out the &#39;front&#39; again.<br>
<br>  -- ryan<br><br>On Tue, Nov 1, 2011 at 1:30 PM, Captain Freako <span dir="ltr">&lt;<a href="mailto:capn.freako@gmail.com">capn.freako@gmail.com</a>&gt;</span> wrote:<br><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
Hi John,<br>
<br>
I&#39;m trying to use the GHCI debugger on this code:<br>
<br>
 20 instance ArrowLoop SF where<br>
 21     loop (SF f) = SF $ \as -&gt;<br>
 22         let (bs, cs) = unzip (f (zip as (stream cs))) in bs<br>
 23       where stream ~(x:xs) = x : stream xs<br>
 24<br>
 25 swap :: (a,b) -&gt; (b,a)<br>
 26 swap (x,y) = (y,x)<br>
<br>
in order to watch the recursion of the `loop&#39; function unfold.<br>
However, when I single step through the code, I never stop on line 22<br>
(where I could, presumably, peek in at `bs&#39; and `cs&#39;, in order to see<br>
them develop):<br>
<br>
*SF&gt; :break swap<br>
Breakpoint 1 activated at SF.hs:26:1-18<br>
*SF&gt; runSF (loop (arr swap)) [1,2,3]<br>
Stopped at SF.hs:26:1-18<br>
_result :: (b, a) = _<br>
[SF.hs:26:1-18] *SF&gt; :step<br>
Stopped at SF.hs:26:14-18<br>
_result :: (b, a) = _<br>
x :: a = _<br>
y :: b = _<br>
[SF.hs:26:14-18] *SF&gt; :<br>
[1Stopped at SF.hs:23:34-42<br>
_result :: [a] = _<br>
xs :: [a] = _<br>
[SF.hs:23:34-42] *SF&gt; :<br>
Stopped at SF.hs:23:13-42<br>
_result :: [a] = _<br>
[SF.hs:23:13-42] *SF&gt; :<br>
Stopped at SF.hs:23:30-42<br>
_result :: [a] = _<br>
x :: a = _<br>
xs :: [a] = _<br>
[SF.hs:23:30-42] *SF&gt; :<br>
(Pattern repeats.)<br>
<br>
Do you have any advice?<br>
<br>
Thanks,<br>
-db<br>
<div class="im"><br>
<br>
<br>
On Mon, Oct 31, 2011 at 3:19 PM, John Lask &lt;<a href="mailto:jvlask@hotmail.com">jvlask@hotmail.com</a>&gt; wrote:<br>
</div><div class="im">&gt; On 1/11/2011 1:35 AM, Captain Freako wrote:<br>
&gt;<br>
&gt; you need to study ArrowLoop and understand that. In the code<br>
<br>
</div><div><div></div><div class="h5">_______________________________________________<br>
Haskell-Cafe mailing list<br>
<a href="mailto:Haskell-Cafe@haskell.org">Haskell-Cafe@haskell.org</a><br>
<a href="http://www.haskell.org/mailman/listinfo/haskell-cafe" target="_blank">http://www.haskell.org/mailman/listinfo/haskell-cafe</a><br>
</div></div></blockquote></div><br>