<div dir="ltr">Hi café.<div><br></div><div style>I&#39;ve come up with a little version of &#39;uniq&#39; that should take into account md5 sums of the file changes... In essence, this:</div><div style><br></div><div style>

<br></div><div style><div>main :: IO ()</div><div>main = getContents</div><div>   &gt;&gt;= mapM check . lines -- PROBLEM!!!!</div><div>   &gt;&gt;= mapM_ (putStrLn . (&quot; --&gt; &quot; ++ )) . strip</div><div><br></div>

<div>check :: String -&gt; IO (String, ABCD)</div><div>check s = (s,) . md5 . Str &lt;$&gt; readFile s</div><div><br></div><div>strip :: (Ord a, Eq b) =&gt; [(a,b)] -&gt; [a]</div><div>strip = concat . uncurry (zipWith look) . (id &amp;&amp;&amp; maps)</div>

<div><br></div><div>look :: (Ord a, Eq b) =&gt; (a,b) -&gt; M.Map a b -&gt; [a]</div><div>look (k,v) m | M.lookup k m == Just v = []</div><div>             | otherwise              = [k]</div><div><br></div><div>maps :: Ord a =&gt; [(a,b)] -&gt; [M.Map a b]</div>

<div>maps = scanl (flip (uncurry M.insert)) M.empty</div><div><br></div><div><br></div><div style>Unfortunately mapM isn&#39;t lazy, so this doesn&#39;t work. I thought this would be a good opportunity to try out the Pipes library for a simple real-world task, but I&#39;ve come up against some issues with using &#39;zip&#39; and &#39;scan&#39; like functions when translating the code.</div>

<div style><br></div><div style>This is what I&#39;ve got so far, but I&#39;m not sure how to proceed:</div><div style><br></div><div style><br></div><div style><div>main :: IO ()</div><div>main = runProxy $ stdinS &gt;-&gt; pipe &gt;-&gt; stdoutD</div>

<div><br></div><div>pipe :: () -&gt; ProxyFast () String () String IO ()</div><div>pipe = mapMD check</div><div>   &gt;-&gt; mapScan</div><div style>  -- zip, check, output go here</div><div>   &gt;-&gt; mapD ((&quot; --&gt; &quot; ++) . show)</div>

<div><br></div><div>mapScan :: () -&gt; ProxyFast () (String, ABCD) () (M.Map String ABCD) IO b</div><div>mapScan = scanlp (uncurry M.insert) (M.empty)</div><div><br></div><div>check :: String -&gt; IO (String, ABCD)</div>

<div>check s = (s,) . md5 . Str &lt;$&gt; readFile s</div><div><br></div><div>-- Utils</div><div><br></div><div>scanlp :: (Monad (p () t a b1 m), Monad m, Functor (p () t a b1 m), Proxy p) =&gt;</div><div>          (t -&gt; b1 -&gt; b1) -&gt; b1 -&gt; () -&gt; p () t a b1 m b</div>

<div>scanlp f a b = do</div><div>  void $ respond a</div><div>  v &lt;- request ()</div><div>  scanlp f (f v a) b</div><div><br></div><div><br></div><div style>There doesn&#39;t seem to be any easy zipLike functions, and having to write my own scan function seems odd. Can someone point me in the right direction for this?</div>

<div style><br></div><div style><br></div><div style>Thanks!</div><div style><br></div><div style> - Lyndon</div></div></div></div>