From d9e5fa673b75cdffbcd0e85cdcc98d706acbb29a Mon Sep 17 00:00:00 2001 From: simonmar Date: Tue, 3 Jul 2001 14:13:32 +0000 Subject: [PATCH] [project @ 2001-07-03 14:13:32 by simonmar] Move generic Maybe and Either definitions from GHC.Maybe to Data.Maybe and Data.Either, and remove GHC.Maybe. --- Data/Dynamic.hs | 6 ++++-- Data/Either.hs | 10 ++++++++-- Data/Maybe.hs | 32 ++++++++++++++++++++++++++++---- GHC/Base.lhs | 4 ++-- GHC/Conc.lhs | 5 +++-- GHC/Enum.lhs | 4 +--- GHC/Exception.lhs | 5 +++-- GHC/Float.lhs | 5 +++-- GHC/IOBase.lhs | 4 ++-- GHC/List.lhs | 4 ++-- GHC/Read.lhs | 6 ++++-- GHC/Show.lhs | 5 +++-- GHC/Weak.lhs | 4 ++-- 13 files changed, 65 insertions(+), 29 deletions(-) diff --git a/Data/Dynamic.hs b/Data/Dynamic.hs index fe3d627..e8643a3 100644 --- a/Data/Dynamic.hs +++ b/Data/Dynamic.hs @@ -9,7 +9,7 @@ -- Stability : experimental -- Portability : portable -- --- $Id: Dynamic.hs,v 1.2 2001/07/03 11:37:49 simonmar Exp $ +-- $Id: Dynamic.hs,v 1.3 2001/07/03 14:13:32 simonmar Exp $ -- -- The Dynamic interface provides basic support for dynamic types. -- @@ -64,9 +64,11 @@ module Data.Dynamic ) where +import Data.Maybe +import Data.Either + #ifdef __GLASGOW_HASKELL__ import GHC.Base -import GHC.Maybe import GHC.Show import GHC.Err import GHC.Num diff --git a/Data/Either.hs b/Data/Either.hs index ea91a48..20dfe47 100644 --- a/Data/Either.hs +++ b/Data/Either.hs @@ -9,7 +9,7 @@ -- Stability : experimental -- Portability : portable -- --- $Id: Either.hs,v 1.2 2001/07/03 11:37:49 simonmar Exp $ +-- $Id: Either.hs,v 1.3 2001/07/03 14:13:32 simonmar Exp $ -- -- The Either type, and associated operations. -- @@ -21,5 +21,11 @@ module Data.Either ( ) where #ifdef __GLASGOW_HASKELL__ -import GHC.Maybe +import GHC.Base #endif + +data Either a b = Left a | Right b deriving (Eq, Ord ) + +either :: (a -> c) -> (b -> c) -> Either a b -> c +either f _ (Left x) = f x +either _ g (Right y) = g y diff --git a/Data/Maybe.hs b/Data/Maybe.hs index de5d121..3f1ffad 100644 --- a/Data/Maybe.hs +++ b/Data/Maybe.hs @@ -9,7 +9,7 @@ -- Stability : experimental -- Portability : portable -- --- $Id: Maybe.hs,v 1.2 2001/07/03 11:37:50 simonmar Exp $ +-- $Id: Maybe.hs,v 1.3 2001/07/03 14:13:32 simonmar Exp $ -- -- The Maybe type, and associated operations. -- @@ -33,12 +33,36 @@ module Data.Maybe ) where #ifdef __GLASGOW_HASKELL__ -import GHC.Err ( error ) -import GHC.List -import GHC.Maybe +import {-# SOURCE #-} GHC.Err ( error ) import GHC.Base #endif +-- --------------------------------------------------------------------------- +-- The Maybe type, and instances + +data Maybe a = Nothing | Just a deriving (Eq, Ord) + +instance Functor Maybe where + fmap _ Nothing = Nothing + fmap f (Just a) = Just (f a) + +instance Monad Maybe where + (Just x) >>= k = k x + Nothing >>= _ = Nothing + + (Just _) >> k = k + Nothing >> _ = Nothing + + return = Just + fail _ = Nothing + +-- --------------------------------------------------------------------------- +-- Functions over Maybe + +maybe :: b -> (a -> b) -> Maybe a -> b +maybe n _ Nothing = n +maybe _ f (Just x) = f x + isJust :: Maybe a -> Bool isJust Nothing = False isJust _ = True diff --git a/GHC/Base.lhs b/GHC/Base.lhs index 968d703..e694e84 100644 --- a/GHC/Base.lhs +++ b/GHC/Base.lhs @@ -1,5 +1,5 @@ % ----------------------------------------------------------------------------- -% $Id: Base.lhs,v 1.2 2001/07/03 11:37:50 simonmar Exp $ +% $Id: Base.lhs,v 1.3 2001/07/03 14:13:32 simonmar Exp $ % % (c) The University of Glasgow, 1992-2000 % @@ -33,7 +33,7 @@ GHC.Show Class: Show, plus instances for GHC.Base/GHC.Tup types GHC.Enum Class: Enum, plus instances for GHC.Base/GHC.Tup types -GHC.Maybe Type: Maybe, plus instances for GHC.Base classes +Data.Maybe Type: Maybe, plus instances for GHC.Base classes GHC.Num Class: Num, plus instances for Int Type: Integer, plus instances for all classes so far (Eq, Ord, Num, Show) diff --git a/GHC/Conc.lhs b/GHC/Conc.lhs index 57daaf8..b847a85 100644 --- a/GHC/Conc.lhs +++ b/GHC/Conc.lhs @@ -1,5 +1,5 @@ % ----------------------------------------------------------------------------- -% $Id: Conc.lhs,v 1.1 2001/06/28 14:15:03 simonmar Exp $ +% $Id: Conc.lhs,v 1.2 2001/07/03 14:13:32 simonmar Exp $ % % (c) The University of Glasgow, 1994-2000 % @@ -40,8 +40,9 @@ module GHC.Conc ) where +import Data.Maybe + import GHC.Base -import GHC.Maybe import GHC.Err ( parError, seqError ) import GHC.IOBase ( IO(..), MVar(..) ) import GHC.Base ( Int(..) ) diff --git a/GHC/Enum.lhs b/GHC/Enum.lhs index 8f1ce75..f5a27fb 100644 --- a/GHC/Enum.lhs +++ b/GHC/Enum.lhs @@ -1,5 +1,5 @@ % ----------------------------------------------------------------------------- -% $Id: Enum.lhs,v 1.2 2001/07/03 11:37:50 simonmar Exp $ +% $Id: Enum.lhs,v 1.3 2001/07/03 14:13:32 simonmar Exp $ % % (c) The University of Glasgow, 1992-2000 % @@ -21,8 +21,6 @@ module GHC.Enum( import {-# SOURCE #-} GHC.Err ( error ) import GHC.Base -import Data.Tuple () -- To make sure we look for the .hi file - default () -- Double isn't available yet \end{code} diff --git a/GHC/Exception.lhs b/GHC/Exception.lhs index abf9a82..ac7237f 100644 --- a/GHC/Exception.lhs +++ b/GHC/Exception.lhs @@ -1,5 +1,5 @@ % ------------------------------------------------------------------------------ -% $Id: Exception.lhs,v 1.1 2001/06/28 14:15:03 simonmar Exp $ +% $Id: Exception.lhs,v 1.2 2001/07/03 14:13:32 simonmar Exp $ % % (c) The University of Glasgow, 1998-2000 % @@ -17,8 +17,9 @@ module GHC.Exception throw, ioError ) where +import Data.Either + import GHC.Base -import GHC.Maybe import GHC.IOBase #endif diff --git a/GHC/Float.lhs b/GHC/Float.lhs index 186d29c..08fa67c 100644 --- a/GHC/Float.lhs +++ b/GHC/Float.lhs @@ -1,5 +1,5 @@ % ------------------------------------------------------------------------------ -% $Id: Float.lhs,v 1.1 2001/06/28 14:15:03 simonmar Exp $ +% $Id: Float.lhs,v 1.2 2001/07/03 14:13:32 simonmar Exp $ % % (c) The University of Glasgow, 1994-2000 % @@ -23,6 +23,8 @@ and the classes module GHC.Float( module GHC.Float, Float#, Double# ) where +import Data.Maybe + import GHC.Base import GHC.List import GHC.Enum @@ -30,7 +32,6 @@ import GHC.Show import GHC.Num import GHC.Real import GHC.Arr -import GHC.Maybe infixr 8 ** \end{code} diff --git a/GHC/IOBase.lhs b/GHC/IOBase.lhs index 7e77363..7750f9a 100644 --- a/GHC/IOBase.lhs +++ b/GHC/IOBase.lhs @@ -1,5 +1,5 @@ % ------------------------------------------------------------------------------ -% $Id: IOBase.lhs,v 1.1 2001/06/28 14:15:03 simonmar Exp $ +% $Id: IOBase.lhs,v 1.2 2001/07/03 14:13:32 simonmar Exp $ % % (c) The University of Glasgow, 1994-2001 % @@ -18,7 +18,7 @@ import GHC.STRef import GHC.Arr import GHC.Base import GHC.Num -- To get fromInteger etc, needed because of -fno-implicit-prelude -import GHC.Maybe ( Maybe(..) ) +import Data.Maybe ( Maybe(..) ) import GHC.Show import GHC.List import GHC.Read diff --git a/GHC/List.lhs b/GHC/List.lhs index 88962b7..07f6d3f 100644 --- a/GHC/List.lhs +++ b/GHC/List.lhs @@ -1,5 +1,5 @@ % ------------------------------------------------------------------------------ -% $Id: List.lhs,v 1.2 2001/07/03 11:37:50 simonmar Exp $ +% $Id: List.lhs,v 1.3 2001/07/03 14:13:32 simonmar Exp $ % % (c) The University of Glasgow, 1994-2000 % @@ -37,7 +37,7 @@ module GHC.List ( import {-# SOURCE #-} GHC.Err ( error ) import Data.Tuple -import GHC.Maybe +import Data.Maybe import GHC.Base infixl 9 !! diff --git a/GHC/Read.lhs b/GHC/Read.lhs index 1e66f85..5332c63 100644 --- a/GHC/Read.lhs +++ b/GHC/Read.lhs @@ -1,5 +1,5 @@ % ------------------------------------------------------------------------------ -% $Id: Read.lhs,v 1.1 2001/06/28 14:15:03 simonmar Exp $ +% $Id: Read.lhs,v 1.2 2001/07/03 14:13:32 simonmar Exp $ % % (c) The University of Glasgow, 1994-2000 % @@ -13,13 +13,15 @@ Instances of the Read class. module GHC.Read where +import Data.Maybe +import Data.Either + import {-# SOURCE #-} GHC.Err ( error ) import GHC.Enum ( Enum(..), maxBound ) import GHC.Num import GHC.Real import GHC.Float import GHC.List -import GHC.Maybe import GHC.Show -- isAlpha etc import GHC.Base \end{code} diff --git a/GHC/Show.lhs b/GHC/Show.lhs index ea882ca..3f83519 100644 --- a/GHC/Show.lhs +++ b/GHC/Show.lhs @@ -1,5 +1,5 @@ % ------------------------------------------------------------------------------ -% $Id: Show.lhs,v 1.2 2001/07/03 11:37:50 simonmar Exp $ +% $Id: Show.lhs,v 1.3 2001/07/03 14:13:32 simonmar Exp $ % % (c) The University of Glasgow, 1992-2000 % @@ -34,7 +34,8 @@ module GHC.Show import {-# SOURCE #-} GHC.Err ( error ) import GHC.Base -import GHC.Maybe +import Data.Maybe +import Data.Either import GHC.List ( (!!), break, dropWhile #ifdef USE_REPORT_PRELUDE , concatMap, foldr1 diff --git a/GHC/Weak.lhs b/GHC/Weak.lhs index b9e5172..95dd3a5 100644 --- a/GHC/Weak.lhs +++ b/GHC/Weak.lhs @@ -1,5 +1,5 @@ % ------------------------------------------------------------------------------ -% $Id: Weak.lhs,v 1.1 2001/06/28 14:15:03 simonmar Exp $ +% $Id: Weak.lhs,v 1.2 2001/07/03 14:13:32 simonmar Exp $ % % (c) The University of Glasgow, 1998-2000 % @@ -13,7 +13,7 @@ module GHC.Weak where import GHC.Prim import GHC.Base -import GHC.Maybe +import Data.Maybe import GHC.IOBase ( IO(..), unIO ) data Weak v = Weak (Weak# v) -- 1.7.10.4