From 7417ce9aeae9b551467ccdb32b354cd4f7569769 Mon Sep 17 00:00:00 2001 From: simonm Date: Mon, 24 Nov 1997 17:50:10 +0000 Subject: [PATCH] [project @ 1997-11-24 17:49:28 by simonm] Pull Maybe and Either out of PrelBase into separate modules in an attempt to make PrelBase a little smaller. --- ghc/lib/ghc/IOBase.lhs | 1 + ghc/lib/ghc/IOHandle.lhs | 1 + ghc/lib/ghc/PrelBase.lhs | 50 ------------------------------------------ ghc/lib/ghc/PrelEither.lhs | 20 +++++++++++++++++ ghc/lib/ghc/PrelList.lhs | 1 + ghc/lib/ghc/PrelMaybe.lhs | 44 +++++++++++++++++++++++++++++++++++++ ghc/lib/ghc/PrelNum.lhs | 2 +- ghc/lib/ghc/PrelRead.lhs | 2 ++ ghc/lib/required/IO.lhs | 2 ++ ghc/lib/required/Maybe.lhs | 1 + ghc/lib/required/Numeric.lhs | 1 + ghc/lib/required/Prelude.lhs | 2 ++ 12 files changed, 76 insertions(+), 51 deletions(-) create mode 100644 ghc/lib/ghc/PrelEither.lhs create mode 100644 ghc/lib/ghc/PrelMaybe.lhs diff --git a/ghc/lib/ghc/IOBase.lhs b/ghc/lib/ghc/IOBase.lhs index d6253db..c920cc8 100644 --- a/ghc/lib/ghc/IOBase.lhs +++ b/ghc/lib/ghc/IOBase.lhs @@ -16,6 +16,7 @@ module IOBase where import {-# SOURCE #-} Error import STBase import PrelTup +import PrelMaybe import Addr import PackBase ( unpackCString ) import PrelBase diff --git a/ghc/lib/ghc/IOHandle.lhs b/ghc/lib/ghc/IOHandle.lhs index 0d1a9fb..b0c3c81 100644 --- a/ghc/lib/ghc/IOHandle.lhs +++ b/ghc/lib/ghc/IOHandle.lhs @@ -23,6 +23,7 @@ import Ix import IOBase import Unsafe ( unsafePerformIO ) import PrelTup +import PrelMaybe import PrelBase import GHC import Addr diff --git a/ghc/lib/ghc/PrelBase.lhs b/ghc/lib/ghc/PrelBase.lhs index 86c9a58..7e780c9 100644 --- a/ghc/lib/ghc/PrelBase.lhs +++ b/ghc/lib/ghc/PrelBase.lhs @@ -309,41 +309,6 @@ otherwise = True %********************************************************* %* * -\subsection{Type @Maybe@} -%* * -%********************************************************* - -\begin{code} -data Maybe a = Nothing | Just a deriving (Eq, Ord, Show {- Read -}) - -maybe :: b -> (a -> b) -> Maybe a -> b -maybe n f Nothing = n -maybe n f (Just x) = f x - -instance Functor Maybe where - map f Nothing = Nothing - map f (Just a) = Just (f a) - -instance Monad Maybe where - (Just x) >>= k = k x - Nothing >>= k = Nothing - - (Just x) >> k = k - Nothing >> k = Nothing - - return = Just - -instance MonadZero Maybe where - zero = Nothing - -instance MonadPlus Maybe where - Nothing ++ ys = ys - xs ++ ys = xs -\end{code} - - -%********************************************************* -%* * \subsection{The @()@ type} %* * %********************************************************* @@ -391,21 +356,6 @@ instance Show () where %********************************************************* %* * -\subsection{Type @Either@} -%* * -%********************************************************* - -\begin{code} -data Either a b = Left a | Right b deriving (Eq, Ord, Show {- Read -} ) - -either :: (a -> c) -> (b -> c) -> Either a b -> c -either f g (Left x) = f x -either f g (Right y) = g y -\end{code} - - -%********************************************************* -%* * \subsection{Type @Ordering@} %* * %********************************************************* diff --git a/ghc/lib/ghc/PrelEither.lhs b/ghc/lib/ghc/PrelEither.lhs new file mode 100644 index 0000000..71969aa --- /dev/null +++ b/ghc/lib/ghc/PrelEither.lhs @@ -0,0 +1,20 @@ +% +% (c) The GRASP/AQUA Project, Glasgow University, 1992-1997 +% +\section[PrelEither]{Module @PrelEither@} + +The @Either@ Type. + +\begin{code} +{-# OPTIONS -fno-implicit-prelude #-} + +module PrelEither where + +import PrelBase + +data Either a b = Left a | Right b deriving (Eq, Ord, Show {- Read -} ) + +either :: (a -> c) -> (b -> c) -> Either a b -> c +either f g (Left x) = f x +either f g (Right y) = g y +\end{code} diff --git a/ghc/lib/ghc/PrelList.lhs b/ghc/lib/ghc/PrelList.lhs index 26be5ae..4ed206b 100644 --- a/ghc/lib/ghc/PrelList.lhs +++ b/ghc/lib/ghc/PrelList.lhs @@ -24,6 +24,7 @@ module PrelList ( import {-# SOURCE #-} Error ( error ) import PrelTup +import PrelMaybe import PrelBase infix 4 `elem`, `notElem` diff --git a/ghc/lib/ghc/PrelMaybe.lhs b/ghc/lib/ghc/PrelMaybe.lhs new file mode 100644 index 0000000..974e5de --- /dev/null +++ b/ghc/lib/ghc/PrelMaybe.lhs @@ -0,0 +1,44 @@ +% +% (c) The GRASP/AQUA Project, Glasgow University, 1992-1996 +% +\section[PrelMaybe]{Module @PrelMaybe@} + +The @Maybe@ type. + +\begin{code} +{-# OPTIONS -fno-implicit-prelude #-} + +module PrelMaybe where + +import PrelBase + +data Maybe a = Nothing | Just a deriving (Eq, Ord, Show {- Read -}) + +maybe :: b -> (a -> b) -> Maybe a -> b +maybe n f Nothing = n +maybe n f (Just x) = f x + +instance Functor Maybe where + map f Nothing = Nothing + map f (Just a) = Just (f a) + +instance Monad Maybe where + (Just x) >>= k = k x + Nothing >>= k = Nothing + + (Just x) >> k = k + Nothing >> k = Nothing + + return = Just + +instance MonadZero Maybe where + zero = Nothing + +instance MonadPlus Maybe where + Nothing ++ ys = ys + xs ++ ys = xs +\end{code} + + + + diff --git a/ghc/lib/ghc/PrelNum.lhs b/ghc/lib/ghc/PrelNum.lhs index 72e6d4a..041214d 100644 --- a/ghc/lib/ghc/PrelNum.lhs +++ b/ghc/lib/ghc/PrelNum.lhs @@ -23,6 +23,7 @@ import PrelBase import GHC import {-# SOURCE #-} Error ( error ) import PrelList +import PrelMaybe import ArrBase ( Array, array, (!) ) import Unsafe ( unsafePerformIO ) @@ -1185,7 +1186,6 @@ integerLogBase b i = in doDiv (i `div` (b^l)) l \end{code} - %********************************************************* %* * \subsection{Numeric primops} diff --git a/ghc/lib/ghc/PrelRead.lhs b/ghc/lib/ghc/PrelRead.lhs index f3a064f..60917b3 100644 --- a/ghc/lib/ghc/PrelRead.lhs +++ b/ghc/lib/ghc/PrelRead.lhs @@ -15,6 +15,8 @@ import {-# SOURCE #-} Error ( error ) import PrelNum import PrelList import PrelTup +import PrelMaybe +import PrelEither import PrelBase \end{code} diff --git a/ghc/lib/required/IO.lhs b/ghc/lib/required/IO.lhs index abf28ec..4e058d3 100644 --- a/ghc/lib/required/IO.lhs +++ b/ghc/lib/required/IO.lhs @@ -40,6 +40,8 @@ import ArrBase ( MutableByteArray(..), newCharArray ) import IOHandle -- much of the real stuff is in here import PackBase ( unpackNBytesST ) import PrelBase +import PrelMaybe +import PrelEither import GHC import Addr diff --git a/ghc/lib/required/Maybe.lhs b/ghc/lib/required/Maybe.lhs index 2c663aa..40b130f 100644 --- a/ghc/lib/required/Maybe.lhs +++ b/ghc/lib/required/Maybe.lhs @@ -23,6 +23,7 @@ module Maybe import Error ( error ) import Monad ( filter ) import PrelList +import PrelMaybe import PrelBase \end{code} diff --git a/ghc/lib/required/Numeric.lhs b/ghc/lib/required/Numeric.lhs index 34b26d1..2dd49a3 100644 --- a/ghc/lib/required/Numeric.lhs +++ b/ghc/lib/required/Numeric.lhs @@ -32,6 +32,7 @@ module Numeric ) where import PrelBase +import PrelMaybe import ArrBase import PrelNum import PrelRead diff --git a/ghc/lib/required/Prelude.lhs b/ghc/lib/required/Prelude.lhs index 088bc2b..92d173f 100644 --- a/ghc/lib/required/Prelude.lhs +++ b/ghc/lib/required/Prelude.lhs @@ -67,6 +67,8 @@ import PrelIO import PrelRead import PrelNum import PrelTup +import PrelMaybe +import PrelEither import Monad import Maybe import Error ( error ) -- 1.7.10.4