From a14ad9bdd6b0922909360f177f3b15f6f41d5779 Mon Sep 17 00:00:00 2001 From: Stephen Diehl Date: Wed, 13 Apr 2016 15:20:15 -0400 Subject: [PATCH 1/7] all non-partial list functions --- src/Protolude.hs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/Protolude.hs b/src/Protolude.hs index d3fc34d76..04bddec92 100644 --- a/src/Protolude.hs +++ b/src/Protolude.hs @@ -105,6 +105,23 @@ import Data.List as X ( , reverse , replicate , take + , sortBy + , sort + , intersperse + , transpose + , subsequences + , permutations + , scanl + , scanr + , iterate + , repeat + , cycle + , unfoldr + , takeWhile + , dropWhile + , group + , inits + , tails , zipWith , zip ) From 26d679e25775db94762b1bd583497268d849b240 Mon Sep 17 00:00:00 2001 From: Stephen Diehl Date: Wed, 13 Apr 2016 16:12:55 -0400 Subject: [PATCH 2/7] explicit base types, IsString export, Proxy --- src/Base.hs | 23 ++++++++++++++++------- src/Protolude.hs | 16 ++++++++++++---- 2 files changed, 28 insertions(+), 11 deletions(-) diff --git a/src/Base.hs b/src/Base.hs index 280c7b11f..791592322 100644 --- a/src/Base.hs +++ b/src/Base.hs @@ -16,17 +16,21 @@ 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.Show as X ( + Show(..) + ) import GHC.Exts as X ( Constraint , Ptr , FunPtr - , the ) import GHC.Base as X ( (++) , seq , asTypeOf + , ord + , maxInt + , minInt ) import System.IO as X ( print @@ -34,11 +38,15 @@ import System.IO as X ( , putStrLn ) -#if ( __GLASGOW_HASKELL__ >= 800 ) -import GHC.Types as X hiding (Any) -#else -import GHC.Types as X -#endif +import GHC.Types as X ( + Bool + , Char + , Int + , Word + , Ordering + , IO + , Coercible + ) infixr 0 $! @@ -47,6 +55,7 @@ f $! x = let !vx = x in f vx #endif + -- Simple Haskell Compiler #if defined(__SHC_HASKELL__) diff --git a/src/Protolude.hs b/src/Protolude.hs index 04bddec92..1ccbf0978 100644 --- a/src/Protolude.hs +++ b/src/Protolude.hs @@ -16,8 +16,6 @@ module Protolude ( LByteString, ) where -{-import qualified Prelude as P-} - import List as X import Show as X import Bool as X @@ -130,6 +128,9 @@ import Data.Set as X (Set) import Data.Sequence as X (Seq) import Data.IntMap as X (IntMap) import Data.IntSet as X (IntSet) +import Data.Proxy as X ( + Proxy(..) + ) -- Monad transformers import Control.Monad.State as X ( @@ -183,10 +184,15 @@ import Data.Int as X import Data.Bits as X import Data.Word as X import Data.Bool as X hiding (bool) -import Data.Char as X (Char) +import Data.Char as X (chr) import Data.Maybe as X hiding (fromJust) import Data.Either as X import Data.Complex as X +import Data.Void as X ( + Void + , absurd + , vacuous + ) import Data.Function as X ( const @@ -197,7 +203,6 @@ import Data.Function as X ( , on ) - -- Genericss import GHC.Generics ( Generic(..) @@ -239,6 +244,8 @@ import Data.String.Conv as X ( , StringConv ) +import Data.String as X (IsString) + -- Printf import Text.Printf as X ( PrintfArg @@ -248,6 +255,7 @@ import Text.Printf as X ( -- IO import System.Exit as X +--import System.Info as X import System.Environment as X (getArgs) import System.IO as X ( Handle From f6fca1059d209f8d152ede3f73376c9a88ad3919 Mon Sep 17 00:00:00 2001 From: Stephen Diehl Date: Wed, 13 Apr 2016 16:28:37 -0400 Subject: [PATCH 3/7] not worth backporting void --- src/Protolude.hs | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/Protolude.hs b/src/Protolude.hs index 1ccbf0978..8b01cd3ff 100644 --- a/src/Protolude.hs +++ b/src/Protolude.hs @@ -188,11 +188,6 @@ import Data.Char as X (chr) import Data.Maybe as X hiding (fromJust) import Data.Either as X import Data.Complex as X -import Data.Void as X ( - Void - , absurd - , vacuous - ) import Data.Function as X ( const From ef52c8d507eae812ca52096efd3b46020c4573be Mon Sep 17 00:00:00 2001 From: Stephen Diehl Date: Wed, 13 Apr 2016 16:36:42 -0400 Subject: [PATCH 4/7] gracefully handle 7.10 modules if present --- src/Base.hs | 2 ++ src/Protolude.hs | 9 +++++++++ 2 files changed, 11 insertions(+) diff --git a/src/Base.hs b/src/Base.hs index 791592322..239f25d18 100644 --- a/src/Base.hs +++ b/src/Base.hs @@ -45,7 +45,9 @@ import GHC.Types as X ( , Word , Ordering , IO +#if ( __GLASGOW_HASKELL__ >= 710 ) , Coercible +#endif ) infixr 0 $! diff --git a/src/Protolude.hs b/src/Protolude.hs index 8b01cd3ff..e9d9efb37 100644 --- a/src/Protolude.hs +++ b/src/Protolude.hs @@ -128,10 +128,19 @@ import Data.Set as X (Set) import Data.Sequence as X (Seq) import Data.IntMap as X (IntMap) import Data.IntSet as X (IntSet) + +#if ( __GLASGOW_HASKELL__ >= 710 ) import Data.Proxy as X ( Proxy(..) ) +import Data.Void as X ( + Void + , absurd + , vacuous + ) +#endif + -- Monad transformers import Control.Monad.State as X ( MonadState From cbaa117b8a3ff67d70fdc8094ed9d6ab5a24a98f Mon Sep 17 00:00:00 2001 From: Stephen Diehl Date: Wed, 13 Apr 2016 16:39:47 -0400 Subject: [PATCH 5/7] brenden's list function --- src/List.hs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/List.hs b/src/List.hs index efde12ce5..c820ae873 100644 --- a/src/List.hs +++ b/src/List.hs @@ -5,6 +5,7 @@ module List ( head, ordNub, sortOn, + list, ) where import Data.List (sortBy) @@ -30,3 +31,8 @@ ordNub l = go Set.empty l if x `Set.member` s then go s xs else x : go (Set.insert x s) xs + +list :: [b] -> (a -> b) -> [a] -> [b] +list def f xs = case xs of + [] -> def + _ -> fmap f xs From 76bc617db9566a2762eb176d7c84e39f58772642 Mon Sep 17 00:00:00 2001 From: Stephen Diehl Date: Wed, 13 Apr 2016 17:09:10 -0400 Subject: [PATCH 6/7] functor include --- src/List.hs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/List.hs b/src/List.hs index c820ae873..6d1261ec8 100644 --- a/src/List.hs +++ b/src/List.hs @@ -13,6 +13,7 @@ import Data.Maybe (Maybe(..)) import Data.Ord (Ord, comparing) import Data.Foldable (Foldable, foldr) import Data.Function ((.)) +import Data.Functor (fmap) import Control.Monad (return) import qualified Data.Set as Set From 8bf3029d011bba7eefba2cc969160152c5a8b1dd Mon Sep 17 00:00:00 2001 From: Stephen Diehl Date: Wed, 13 Apr 2016 18:39:39 -0400 Subject: [PATCH 7/7] design points in readme --- README.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/README.md b/README.md index adff75ad5..49483fdcc 100644 --- a/README.md +++ b/README.md @@ -2,9 +2,23 @@ Protolude ========= [![Build Status](https://travis-ci.org/sdiehl/protolude.svg?branch=master)](https://travis-ci.org/sdiehl/protolude) +[![Hackage](https://img.shields.io/hackage/v/protolude.svg)](https://hackage.haskell.org/package/protolude) A sensible starting Prelude for building custom Preludes. +Design points: + +* Banishes String. +* Banishes partial functions. +* compiler warning on bottoms. +* Foldable / Traversable by default. +* Polymorphic string IO functions. +* Automatic string conversions. +* Type synonyms for major data structures. +* Basic monad transformers in scope by default. +* Unsafe functions are prefixed with "unsafe" in separate module. +* Compiler agnostic, GHC internal modules are abstracted out into Base. + Supports: * GHC 7.6.1