[project @ 2001-07-03 14:13:32 by simonmar]
authorsimonmar <unknown>
Tue, 3 Jul 2001 14:13:32 +0000 (14:13 +0000)
committersimonmar <unknown>
Tue, 3 Jul 2001 14:13:32 +0000 (14:13 +0000)
Move generic Maybe and Either definitions from GHC.Maybe to Data.Maybe
and Data.Either, and remove GHC.Maybe.

13 files changed:
Data/Dynamic.hs
Data/Either.hs
Data/Maybe.hs
GHC/Base.lhs
GHC/Conc.lhs
GHC/Enum.lhs
GHC/Exception.lhs
GHC/Float.lhs
GHC/IOBase.lhs
GHC/List.lhs
GHC/Read.lhs
GHC/Show.lhs
GHC/Weak.lhs

index fe3d627..e8643a3 100644 (file)
@@ -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
index ea91a48..20dfe47 100644 (file)
@@ -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
index de5d121..3f1ffad 100644 (file)
@@ -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
index 968d703..e694e84 100644 (file)
@@ -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)
index 57daaf8..b847a85 100644 (file)
@@ -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(..) )
index 8f1ce75..f5a27fb 100644 (file)
@@ -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}
 
index abf9a82..ac7237f 100644 (file)
@@ -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
index 186d29c..08fa67c 100644 (file)
@@ -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}
index 7e77363..7750f9a 100644 (file)
@@ -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
index 88962b7..07f6d3f 100644 (file)
@@ -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  !!
index 1e66f85..5332c63 100644 (file)
@@ -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}
index ea882ca..3f83519 100644 (file)
@@ -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
index b9e5172..95dd3a5 100644 (file)
@@ -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)