X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=compiler%2Futils%2FMaybes.lhs;h=c9924f7e4b32607bf6ae62ce82877153600b1c57;hb=9fddc2160c524d4fefb9fc8a42704f812aef7bf3;hp=3c9bd693e6d944f8bfe23f7c59f728bb60ee090b;hpb=0065d5ab628975892cea1ec7303f968c3338cbe1;p=ghc-hetmet.git diff --git a/compiler/utils/Maybes.lhs b/compiler/utils/Maybes.lhs index 3c9bd69..c9924f7 100644 --- a/compiler/utils/Maybes.lhs +++ b/compiler/utils/Maybes.lhs @@ -1,14 +1,21 @@ % +% (c) The University of Glasgow 2006 % (c) The GRASP/AQUA Project, Glasgow University, 1992-1998 % -\section[Maybes]{The `Maybe' types and associated utility functions} \begin{code} +{-# OPTIONS -w #-} +-- The above warning supression flag is a temporary kludge. +-- While working on this module you are encouraged to remove it and fix +-- any warnings in the module. See +-- http://hackage.haskell.org/trac/ghc/wiki/Commentary/CodingStyle#Warnings +-- for details + module Maybes ( - module Maybe, -- Re-export all of Maybe + module Data.Maybe, -- Re-export all of Maybe MaybeErr(..), -- Instance of Monad - failME, + failME, isSuccess, orElse, mapCatMaybes, @@ -17,13 +24,12 @@ module Maybes ( expectJust, maybeToBool, - thenMaybe, seqMaybe, returnMaybe, failMaybe + thenMaybe, seqMaybe, returnMaybe, failMaybe, fmapMMaybe ) where #include "HsVersions.h" -import Maybe - +import Data.Maybe infixr 4 `orElse` \end{code} @@ -101,6 +107,11 @@ failMaybe = Nothing orElse :: Maybe a -> a -> a (Just x) `orElse` y = x Nothing `orElse` y = y + +fmapMMaybe :: Monad m => (a -> m b) -> Maybe a -> m (Maybe b) +fmapMMaybe f Nothing = return Nothing +fmapMMaybe f (Just x) = f x >>= \x' -> return (Just x') + \end{code} @@ -118,6 +129,10 @@ instance Monad (MaybeErr err) where Succeeded v >>= k = k v Failed e >>= k = Failed e +isSuccess :: MaybeErr err val -> Bool +isSuccess (Succeeded {}) = True +isSuccess (Failed {}) = False + failME :: err -> MaybeErr err val failME e = Failed e \end{code}