[commit: haddock] ghc-7.6: runtests.hs: Use listToMaybe/fromMaybe instead of safeHead/maybe (bfaff48)

Simon Hengel <[email protected]>
Newsgroups gmane.comp.lang.haskell.cvs.ghc
Message-ID <[email protected]>
Repository : ssh://darcs.haskell.org//srv/darcs/haddock

On branch  : ghc-7.6

http://hackage.haskell.org/trac/ghc/changeset/bfaff48e91dd9f2f3d94739851ab18e7d872c7ff

>---------------------------------------------------------------

commit bfaff48e91dd9f2f3d94739851ab18e7d872c7ff
Author: Simon Hengel <[email protected]>
Date:   Sun Oct 7 18:06:08 2012 +0200

    runtests.hs: Use listToMaybe/fromMaybe instead of safeHead/maybe

>---------------------------------------------------------------

 tests/html-tests/runtests.hs |   14 +++++---------
 1 files changed, 5 insertions(+), 9 deletions(-)

diff --git a/tests/html-tests/runtests.hs b/tests/html-tests/runtests.hs
index 2f218d1..28bf2f7 100644
--- a/tests/html-tests/runtests.hs
+++ b/tests/html-tests/runtests.hs
@@ -68,12 +68,12 @@ test = do
   (_, conf) <- configure normal (Just ghcPath) Nothing defaultProgramConfiguration
   pkgIndex <- getInstalledPackages normal [GlobalPackageDB] conf
   let mkDep pkgName =
-        maybe (error "Couldn't find test dependencies") id $ do
+        fromMaybe (error "Couldn't find test dependencies") $ do
           let pkgs = lookupPackageName pkgIndex (PackageName pkgName)
-          (_, pkgs') <- safeHead pkgs
-          pkg <- safeHead pkgs'
-          ifacePath <- safeHead (haddockInterfaces pkg)
-          htmlPath <- safeHead (haddockHTMLs pkg)
+          (_, pkgs') <- listToMaybe pkgs
+          pkg <- listToMaybe pkgs'
+          ifacePath <- listToMaybe (haddockInterfaces pkg)
+          htmlPath <- listToMaybe (haddockHTMLs pkg)
           return ("-i " ++ htmlPath ++ "," ++ ifacePath)
 
   let base    = mkDep "base"
@@ -90,10 +90,6 @@ test = do
   wait handle "*** Haddock run failed! Exiting."
   check mods (if not (null args) && args !! 0 == "all" then False else True)
   where
-
-    safeHead :: [a] -> Maybe a
-    safeHead xs = case xs of x : _ -> Just x; [] -> Nothing
-
     wait :: ProcessHandle -> String -> IO ()
     wait h msg = do
       r <- waitForProcess h
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.