<div dir="ltr">Hi café.<div><br></div><div style>I've come up with a little version of 'uniq' 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> >>= mapM check . lines -- PROBLEM!!!!</div><div> >>= mapM_ (putStrLn . (" --> " ++ )) . strip</div><div><br></div>
<div>check :: String -> IO (String, ABCD)</div><div>check s = (s,) . md5 . Str <$> readFile s</div><div><br></div><div>strip :: (Ord a, Eq b) => [(a,b)] -> [a]</div><div>strip = concat . uncurry (zipWith look) . (id &&& maps)</div>
<div><br></div><div>look :: (Ord a, Eq b) => (a,b) -> M.Map a b -> [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 => [(a,b)] -> [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't lazy, so this doesn't work. I thought this would be a good opportunity to try out the Pipes library for a simple real-world task, but I've come up against some issues with using 'zip' and 'scan' like functions when translating the code.</div>
<div style><br></div><div style>This is what I've got so far, but I'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 >-> pipe >-> stdoutD</div>
<div><br></div><div>pipe :: () -> ProxyFast () String () String IO ()</div><div>pipe = mapMD check</div><div> >-> mapScan</div><div style> -- zip, check, output go here</div><div> >-> mapD ((" --> " ++) . show)</div>
<div><br></div><div>mapScan :: () -> 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 -> IO (String, ABCD)</div>
<div>check s = (s,) . md5 . Str <$> 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) =></div><div> (t -> b1 -> b1) -> b1 -> () -> p () t a b1 m b</div>
<div>scanlp f a b = do</div><div> void $ respond a</div><div> v <- request ()</div><div> scanlp f (f v a) b</div><div><br></div><div><br></div><div style>There doesn'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>