-- 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.
--
) 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
-- 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.
--
) 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
-- 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.
--
) 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
% -----------------------------------------------------------------------------
-% $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
%
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)
% -----------------------------------------------------------------------------
-% $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
%
) where
+import Data.Maybe
+
import GHC.Base
-import GHC.Maybe
import GHC.Err ( parError, seqError )
import GHC.IOBase ( IO(..), MVar(..) )
import GHC.Base ( Int(..) )
% -----------------------------------------------------------------------------
-% $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
%
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}
% ------------------------------------------------------------------------------
-% $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
%
throw, ioError )
where
+import Data.Either
+
import GHC.Base
-import GHC.Maybe
import GHC.IOBase
#endif
% ------------------------------------------------------------------------------
-% $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
%
module GHC.Float( module GHC.Float, Float#, Double# ) where
+import Data.Maybe
+
import GHC.Base
import GHC.List
import GHC.Enum
import GHC.Num
import GHC.Real
import GHC.Arr
-import GHC.Maybe
infixr 8 **
\end{code}
% ------------------------------------------------------------------------------
-% $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
%
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
% ------------------------------------------------------------------------------
-% $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
%
import {-# SOURCE #-} GHC.Err ( error )
import Data.Tuple
-import GHC.Maybe
+import Data.Maybe
import GHC.Base
infixl 9 !!
% ------------------------------------------------------------------------------
-% $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
%
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}
% ------------------------------------------------------------------------------
-% $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
%
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
% ------------------------------------------------------------------------------
-% $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
%
import GHC.Prim
import GHC.Base
-import GHC.Maybe
+import Data.Maybe
import GHC.IOBase ( IO(..), unIO )
data Weak v = Weak (Weak# v)