From c643136e32b99a650a6fdea0731ea5af275f6866 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Mon, 31 Oct 2011 23:39:55 -0400 Subject: playing with >=> Apparently in haskell if you teach a man to fish, he'll write more pointfree code. --- Backend/SHA.hs | 2 +- Command/Fsck.hs | 2 +- Limit.hs | 4 ++-- Utility/Misc.hs | 5 +++-- 4 files changed, 7 insertions(+), 6 deletions(-) diff --git a/Backend/SHA.hs b/Backend/SHA.hs index 3a54a8871..3f210df1f 100644 --- a/Backend/SHA.hs +++ b/Backend/SHA.hs @@ -83,7 +83,7 @@ keyValue size file = do {- Extension preserving keys. -} keyValueE :: SHASize -> FilePath -> Annex (Maybe Key) -keyValueE size file = keyValue size file >>= maybe (return Nothing) addE +keyValueE size file = keyValue >>= maybe (return Nothing) addE where addE k = return $ Just $ k { keyName = keyName k ++ extension diff --git a/Command/Fsck.hs b/Command/Fsck.hs index 8d6f03d76..d1abb29e3 100644 --- a/Command/Fsck.hs +++ b/Command/Fsck.hs @@ -69,7 +69,7 @@ performBare key backend = check ] check :: [Annex Bool] -> CommandPerform -check s = sequence s >>= dispatch +check = sequence >=> dispatch where dispatch vs | all (== True) vs = next $ return True diff --git a/Limit.hs b/Limit.hs index 490577e80..3ae949bfb 100644 --- a/Limit.hs +++ b/Limit.hs @@ -67,7 +67,7 @@ addExclude glob = addLimit $ return . notExcluded addIn :: String -> Annex () addIn name = addLimit $ check $ if name == "." then inAnnex else inremote where - check a f = Backend.lookupFile f >>= handle a + check a = Backend.lookupFile >=> handle a handle _ Nothing = return False handle a (Just (key, _)) = a key inremote key = do @@ -83,7 +83,7 @@ addCopies num = Nothing -> error "bad number for --copies" Just n -> addLimit $ check n where - check n f = Backend.lookupFile f >>= handle n + check n = Backend.lookupFile >=> handle n handle _ Nothing = return False handle n (Just (key, _)) = do us <- keyLocations key diff --git a/Utility/Misc.hs b/Utility/Misc.hs index bc1834774..b3bf22612 100644 --- a/Utility/Misc.hs +++ b/Utility/Misc.hs @@ -8,15 +8,16 @@ module Utility.Misc where import System.IO +import Control.Monad {- A version of hgetContents that is not lazy. Ensures file is - all read before it gets closed. -} hGetContentsStrict :: Handle -> IO String -hGetContentsStrict h = hGetContents h >>= \s -> length s `seq` return s +hGetContentsStrict = hGetContents >=> \s -> length s `seq` return s {- A version of readFile that is not lazy. -} readFileStrict :: FilePath -> IO String -readFileStrict f = readFile f >>= \s -> length s `seq` return s +readFileStrict = readFile >=> \s -> length s `seq` return s {- Attempts to read a value from a String. -} readMaybe :: (Read a) => String -> Maybe a -- cgit v1.2.3