From 5388b8cd4b0407749e17139d6392ee7210e9ed2e Mon Sep 17 00:00:00 2001 From: Stephen Diehl Date: Wed, 13 Apr 2016 13:51:47 -0400 Subject: [PATCH] Squashed commit of the following: commit a6f62265f345c8b7a7226515171752586b0d66e5 Author: Stephen Diehl Date: Wed Apr 13 13:41:05 2016 -0400 bump version commit 1a809623cd1484ce215612e6b3ecef15015bc602 Author: Stephen Diehl Date: Wed Apr 13 13:26:11 2016 -0400 masking for ghc 8.0 specific type commit 54bafb0bb80c8450863eac53a1f3a20a21c8b0c9 Author: Stephen Diehl Date: Wed Apr 13 12:55:08 2016 -0400 bump ghc-prim for GHC 8.0 compat commit 8808d5f37369107b3e5961255089a8a9e02bf3d5 Author: Stephen Diehl Date: Wed Apr 13 12:53:39 2016 -0400 expose base State transformers commit 05c32a4542aa66f715aea3855e140f74e97d4852 Author: Stephen Diehl Date: Wed Apr 13 12:46:00 2016 -0400 adds compiler-independent base module --- protolude.cabal | 30 ++++++++++++--------- src/Applicative.hs | 5 ++-- src/Base.hs | 57 +++++++++++++++++++++++++++++++++++++++ src/Monad.hs | 4 +-- src/Protolude.hs | 67 +++++++++++++++++++--------------------------- src/Show.hs | 18 +++++++------ src/Unsafe.hs | 35 +++++++++++++----------- 7 files changed, 136 insertions(+), 80 deletions(-) create mode 100644 src/Base.hs diff --git a/protolude.cabal b/protolude.cabal index 2b570cd83..f4b82b499 100644 --- a/protolude.cabal +++ b/protolude.cabal @@ -1,5 +1,5 @@ name: protolude -version: 0.1.1 +version: 0.1.2 synopsis: A sensible set of defaults for writing custom Preludes. description: A sensible set of defaults for writing custom Preludes. homepage: https://github.com/sdiehl/protolude @@ -33,37 +33,41 @@ Source-Repository head library exposed-modules: Protolude + Unsafe other-modules: + Base Applicative Bool Debug List Monad Show - Unsafe Either Functor Bifunctor default-extensions: NoImplicitPrelude + OverloadedStrings + MultiParamTypeClasses ghc-options: -Wall build-depends: - base >= 4.6 && <4.10, - safe >= 0.3 && <0.4, - async >= 2.1 && <2.2, - deepseq >= 1.3 && <= 1.5, - containers >= 0.5 && <0.6, - semiring-simple >= 0.1 && <1.1, - mtl >= 2.1 && <2.3, - transformers >= 0.4 && < 0.6, - text >= 1.2 && <1.3, - stm >= 2.4 && <2.5, - string-conv >= 0.1 && <0.2, + base >= 4.6 && <4.10, + ghc-prim >= 0.3 && <0.6, + safe >= 0.3 && <0.4, + async >= 2.1 && <2.2, + deepseq >= 1.3 && <= 1.5, + containers >= 0.5 && <0.6, + semiring-simple >= 0.1 && <1.1, + mtl >= 2.1 && <2.3, + transformers >= 0.4 && < 0.6, + text >= 1.2 && <1.3, + stm >= 2.4 && <2.5, + string-conv >= 0.1 && <0.2, bytestring >= 0.10 && <0.11 hs-source-dirs: src diff --git a/src/Applicative.hs b/src/Applicative.hs index e58d8eac0..fe2cbed97 100644 --- a/src/Applicative.hs +++ b/src/Applicative.hs @@ -7,9 +7,10 @@ module Applicative ( eitherA, ) where -import Data.Monoid +import Data.Bool (Bool) +import Data.Either (Either(..)) +import Data.Monoid (Monoid(..)) import Control.Applicative -import Prelude (Bool, Either(..)) orAlt :: (Alternative f, Monoid a) => f a -> f a orAlt f = f <|> pure mempty diff --git a/src/Base.hs b/src/Base.hs new file mode 100644 index 000000000..280c7b11f --- /dev/null +++ b/src/Base.hs @@ -0,0 +1,57 @@ +{-# LANGUAGE CPP #-} +{-# LANGUAGE Unsafe #-} +{-# LANGUAGE BangPatterns #-} +{-# LANGUAGE NoImplicitPrelude #-} + +module Base ( + module X, + ($!), +) where + +-- Glorious Glashgow Haskell Compiler +#if defined(__GLASGOW_HASKELL__) && ( __GLASGOW_HASKELL__ >= 600 ) + +-- Base GHC types +import GHC.Num as X +import GHC.Enum as X +import GHC.Real as X +import GHC.Float as X +import GHC.Show as X +import GHC.Exts as X ( + Constraint + , Ptr + , FunPtr + , the + ) +import GHC.Base as X ( + (++) + , seq + , asTypeOf + ) +import System.IO as X ( + print + , putStr + , putStrLn + ) + +#if ( __GLASGOW_HASKELL__ >= 800 ) +import GHC.Types as X hiding (Any) +#else +import GHC.Types as X +#endif + +infixr 0 $! + +($!) :: (a -> b) -> a -> b +f $! x = let !vx = x in f vx + +#endif + +-- Simple Haskell Compiler +#if defined(__SHC_HASKELL__) + +import SHC.Prim as X +import SHC.Types as X +import SHC.Classes as X + +#endif diff --git a/src/Monad.hs b/src/Monad.hs index 106bf493d..0befd9cec 100644 --- a/src/Monad.hs +++ b/src/Monad.hs @@ -1,5 +1,5 @@ {-# LANGUAGE CPP #-} -{-# LANGUAGE Safe #-} +{-# LANGUAGE Trustworthy #-} {-# LANGUAGE NoImplicitPrelude #-} module Monad ( @@ -39,8 +39,8 @@ module Monad ( , (<$!>) ) where +import Base (seq) import Data.List (concat) -import Prelude (seq) #if (__GLASGOW_HASKELL__ >= 710) import Control.Monad hiding ((<$!>)) diff --git a/src/Protolude.hs b/src/Protolude.hs index 304b3200b..d3fc34d76 100644 --- a/src/Protolude.hs +++ b/src/Protolude.hs @@ -1,13 +1,13 @@ {-# LANGUAGE CPP #-} +{-# LANGUAGE Trustworthy #-} {-# LANGUAGE NoImplicitPrelude #-} {-# OPTIONS_GHC -fno-warn-unused-imports #-} module Protolude ( module X, + module Base, identity, - bool, (&), - ($!), uncons, applyN, print, @@ -16,16 +16,23 @@ module Protolude ( LByteString, ) where -import qualified Prelude as P +{-import qualified Prelude as P-} -import qualified List as X -import qualified Show as X -import qualified Bool as X -import qualified Debug as X -import qualified Monad as X -import qualified Functor as X -import qualified Either as X -import qualified Applicative as X +import List as X +import Show as X +import Bool as X +import Debug as X +import Monad as X +import Functor as X +import Either as X +import Applicative as X + +import Base as Base hiding ( + putStr + , putStrLn + , print + ) +import qualified Base as PBase -- Maybe'ized version of partial functions import Safe as X ( @@ -88,7 +95,6 @@ import Control.DeepSeq as X ( -- Data structures import Data.Tuple as X -import Data.Semiring as X import Data.List as X ( splitAt , break @@ -99,6 +105,8 @@ import Data.List as X ( , reverse , replicate , take + , zipWith + , zip ) import Data.Map as X (Map) import Data.Set as X (Set) @@ -117,6 +125,10 @@ import Control.Monad.State as X ( , modify , withState + , runState + , execState + , evalState + , runStateT , execStateT , evalStateT @@ -168,24 +180,6 @@ import Data.Function as X ( , on ) --- Base GHC types -import GHC.IO as X (IO) -import GHC.Num as X -import GHC.Enum as X -import GHC.Real as X -import GHC.Float as X -import GHC.Show as X -import GHC.Exts as X ( - Constraint - , Ptr - , FunPtr - , the - ) -import GHC.Base as X ( - (++) - , seq - , asTypeOf - ) -- Genericss import GHC.Generics ( @@ -225,6 +219,7 @@ import Data.String.Conv as X ( , toS , toSL , Leniency(..) + , StringConv ) -- Printf @@ -270,14 +265,6 @@ infixl 1 & (&) :: a -> (a -> b) -> b x & f = f x -infixr 0 $! - -($!) :: (a -> b) -> a -> b -($!) = (P.$!) - -bool :: a -> a -> Bool -> a -bool f t b = if b then t else f - identity :: a -> a identity x = x @@ -288,5 +275,5 @@ uncons (x:xs) = Just (x, xs) applyN :: Int -> (a -> a) -> a -> a applyN n f = X.foldr (.) identity (X.replicate n f) -print :: (X.MonadIO m, P.Show a) => a -> m () -print = liftIO . P.print +print :: (X.MonadIO m, PBase.Show a) => a -> m () +print = liftIO . PBase.print diff --git a/src/Show.hs b/src/Show.hs index 321aadb5a..a4beda42f 100644 --- a/src/Show.hs +++ b/src/Show.hs @@ -1,8 +1,9 @@ -{-# LANGUAGE Safe #-} +{-# LANGUAGE Trustworthy #-} {-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE FlexibleInstances #-} {-# LANGUAGE NoImplicitPrelude #-} {-# LANGUAGE TypeSynonymInstances #-} +{-# LANGUAGE ExtendedDefaultRules #-} module Show ( Print(..), @@ -10,8 +11,8 @@ module Show ( putLText, ) where -import Prelude ((.), Char, IO) -import qualified Prelude +import qualified Base +import Data.Function ((.)) import Control.Monad.IO.Class (MonadIO, liftIO) import qualified Data.ByteString.Char8 as BS @@ -23,6 +24,7 @@ import qualified Data.Text.IO as T import qualified Data.Text.Lazy as TL import qualified Data.Text.Lazy.IO as TL + class Print a where putStr :: MonadIO m => a -> m () putStrLn :: MonadIO m => a -> m () @@ -43,15 +45,15 @@ instance Print BL.ByteString where putStr = liftIO . BL.putStr putStrLn = liftIO . BL.putStrLn -instance Print [Char] where - putStr = liftIO . Prelude.putStr - putStrLn = liftIO . Prelude.putStrLn +instance Print [Base.Char] where + putStr = liftIO . Base.putStr + putStrLn = liftIO . Base.putStrLn -- For forcing type inference putText :: MonadIO m => T.Text -> m () putText = putStrLn -{-# SPECIALIZE putText :: T.Text -> IO () #-} +{-# SPECIALIZE putText :: T.Text -> Base.IO () #-} putLText :: MonadIO m => TL.Text -> m () putLText = putStrLn -{-# SPECIALIZE putLText :: TL.Text -> IO () #-} +{-# SPECIALIZE putLText :: TL.Text -> Base.IO () #-} diff --git a/src/Unsafe.hs b/src/Unsafe.hs index 49d0eb0d7..5e0ba5b83 100644 --- a/src/Unsafe.hs +++ b/src/Unsafe.hs @@ -1,28 +1,33 @@ +{-# LANGUAGE Unsafe #-} {-# LANGUAGE NoImplicitPrelude #-} -module Unsafe where +module Unsafe ( + unsafeHead, + unsafeTail, + unsafeInit, + unsafeLast, + fromJust, + unsafeIndex, +) where -import qualified Prelude -import qualified Data.Maybe -import qualified Data.List +import Base (Int) +import qualified Data.List as List +import qualified Data.Maybe as Maybe unsafeHead :: [a] -> a -unsafeHead = Prelude.head +unsafeHead = List.head unsafeTail :: [a] -> [a] -unsafeTail = Prelude.tail +unsafeTail = List.tail unsafeInit :: [a] -> [a] -unsafeInit = Prelude.init +unsafeInit = List.init unsafeLast :: [a] -> a -unsafeLast = Prelude.last +unsafeLast = List.last -fromJust :: Prelude.Maybe a -> a -fromJust = Data.Maybe.fromJust +fromJust :: Maybe.Maybe a -> a +fromJust = Maybe.fromJust -unsafeIndex :: [a] -> Prelude.Int -> a -unsafeIndex = (Data.List.!!) - -(!!) :: [a] -> Prelude.Int -> a -(!!) = (Data.List.!!) +unsafeIndex :: [a] -> Int -> a +unsafeIndex = (List.!!)