universum 1.6.1 → 1.7.0
raw patch · 32 files changed
+273/−319 lines, 32 filesdep ~basePVP ok
version bump matches the API change (PVP)
Dependency ranges changed: base
API changes (from Hackage documentation)
- Universum.Base: maximumBy :: Foldable t => (a -> a -> Ordering) -> t a -> a
- Universum.Base: minimumBy :: Foldable t => (a -> a -> Ordering) -> t a -> a
- Universum.Container.Class: foldl1 :: Container t => (Element t -> Element t -> Element t) -> t -> Element t
- Universum.Container.Class: foldr1 :: Container t => (Element t -> Element t -> Element t) -> t -> Element t
- Universum.Container.Class: maximum :: (Container t, Foldable f, t ~ f a, Element t ~ a, Ord (Element t)) => t -> Element t
- Universum.Container.Class: minimum :: (Container t, Foldable f, t ~ f a, Element t ~ a, Ord (Element t)) => t -> Element t
+ Universum.Container: -- <a>Text</a>, <a>IntSet</a>, etc.) so we can't implement nice interface
+ Universum.Container: -- associated type family instead of top-level family gives you more
+ Universum.Container: -- control over element types.
+ Universum.Container: -- family because some containers are monomorphic over element type (like
+ Universum.Container: -- using old higher-kinded types approach. Implementing this as an
+ Universum.Container: -- | Type of value of the mapping.
+ Universum.Container: all :: Container t => (Element t -> Bool) -> t -> Bool
+ Universum.Container: and :: (Container t, Element t ~ Bool) => t -> Bool
+ Universum.Container: any :: Container t => (Element t -> Bool) -> t -> Bool
+ Universum.Container: asum :: (Container t, Alternative f, Element t ~ f a) => t -> f a
+ Universum.Container: class Container t where {
+ Universum.Container: class One x where {
+ Universum.Container: class ToPairs t where {
+ Universum.Container: elem :: (Container t, Foldable f, t ~ f a, Element t ~ a, Eq a) => Element t -> t -> Bool
+ Universum.Container: elems :: ToPairs t => t -> [Val t]
+ Universum.Container: find :: Container t => (Element t -> Bool) -> t -> Maybe (Element t)
+ Universum.Container: flipfoldl' :: (Container t, Element t ~ a) => (a -> b -> b) -> b -> t -> b
+ Universum.Container: fold :: (Container t, Monoid (Element t)) => t -> Element t
+ Universum.Container: foldMap :: (Container t, Monoid m) => (Element t -> m) -> t -> m
+ Universum.Container: foldl :: (Container t, Foldable f, t ~ f a, Element t ~ a) => (b -> Element t -> b) -> b -> t -> b
+ Universum.Container: foldl' :: (Container t, Foldable f, t ~ f a, Element t ~ a) => (b -> Element t -> b) -> b -> t -> b
+ Universum.Container: foldr :: (Container t, Foldable f, t ~ f a, Element t ~ a) => (Element t -> b -> b) -> b -> t -> b
+ Universum.Container: foldr' :: Container t => (Element t -> b -> b) -> b -> t -> b
+ Universum.Container: forM_ :: (Container t, Monad m) => t -> (Element t -> m b) -> m ()
+ Universum.Container: for_ :: (Container t, Applicative f) => t -> (Element t -> f b) -> f ()
+ Universum.Container: keys :: ToPairs t => t -> [Key t]
+ Universum.Container: length :: (Container t, Foldable f, t ~ f a) => t -> Int
+ Universum.Container: mapM_ :: (Container t, Monad m) => (Element t -> m b) -> t -> m ()
+ Universum.Container: notElem :: (Container t, Eq (Element t)) => Element t -> t -> Bool
+ Universum.Container: null :: (Container t, Foldable f, t ~ f a) => t -> Bool
+ Universum.Container: one :: One x => OneItem x -> x
+ Universum.Container: or :: (Container t, Element t ~ Bool) => t -> Bool
+ Universum.Container: product :: (Container t, Num (Element t)) => t -> Element t
+ Universum.Container: safeFoldl1 :: Container t => (Element t -> Element t -> Element t) -> t -> Maybe (Element t)
+ Universum.Container: safeFoldr1 :: Container t => (Element t -> Element t -> Element t) -> t -> Maybe (Element t)
+ Universum.Container: safeHead :: Container t => t -> Maybe (Element t)
+ Universum.Container: safeMaximum :: (Container t, Foldable f, t ~ f a, Element t ~ a, Ord (Element t)) => t -> Maybe (Element t)
+ Universum.Container: safeMinimum :: (Container t, Foldable f, t ~ f a, Element t ~ a, Ord (Element t)) => t -> Maybe (Element t)
+ Universum.Container: sequenceA_ :: (Container t, Applicative f, Element t ~ f a) => t -> f ()
+ Universum.Container: sequence_ :: (Container t, Monad m, Element t ~ m a) => t -> m ()
+ Universum.Container: sum :: (Container t, Num (Element t)) => t -> Element t
+ Universum.Container: toList :: (Container t, Foldable f, t ~ f a, Element t ~ a) => t -> [Element t]
+ Universum.Container: toPairs :: ToPairs t => t -> [(Key t, Val t)]
+ Universum.Container: traverse_ :: (Container t, Applicative f) => (Element t -> f b) -> t -> f ()
+ Universum.Container: type Element t = ElementDefault t;
+ Universum.Container: type family Val t :: Type;
+ Universum.Container: }
+ Universum.Container.Class: checkingNotNull :: Container t => (t -> Element t) -> t -> Maybe (Element t)
+ Universum.Container.Class: safeFoldl1 :: Container t => (Element t -> Element t -> Element t) -> t -> Maybe (Element t)
+ Universum.Container.Class: safeFoldr1 :: Container t => (Element t -> Element t -> Element t) -> t -> Maybe (Element t)
+ Universum.Container.Class: safeMaximum :: (Container t, Foldable f, t ~ f a, Element t ~ a, Ord (Element t)) => t -> Maybe (Element t)
+ Universum.Container.Class: safeMinimum :: (Container t, Foldable f, t ~ f a, Element t ~ a, Ord (Element t)) => t -> Maybe (Element t)
+ Universum.List.Safe: foldl1 :: (a -> a -> a) -> NonEmpty a -> a
+ Universum.List.Safe: foldr1 :: (a -> a -> a) -> NonEmpty a -> a
+ Universum.List.Safe: maximum :: Ord a => NonEmpty a -> a
+ Universum.List.Safe: maximumBy :: (a -> a -> Ordering) -> NonEmpty a -> a
+ Universum.List.Safe: minimum :: Ord a => NonEmpty a -> a
+ Universum.List.Safe: minimumBy :: (a -> a -> Ordering) -> NonEmpty a -> a
+ Universum.Unsafe: foldl1 :: Foldable t => (a -> a -> a) -> t a -> a
+ Universum.Unsafe: foldr1 :: Foldable t => (a -> a -> a) -> t a -> a
+ Universum.Unsafe: maximum :: (Foldable t, Ord a) => t a -> a
+ Universum.Unsafe: maximumBy :: Foldable t => (a -> a -> Ordering) -> t a -> a
+ Universum.Unsafe: minimum :: (Foldable t, Ord a) => t a -> a
+ Universum.Unsafe: minimumBy :: Foldable t => (a -> a -> Ordering) -> t a -> a
- Universum.Container.Class: length :: (Container t, Foldable f, t ~ f a, Element t ~ a) => t -> Int
+ Universum.Container.Class: length :: (Container t, Foldable f, t ~ f a) => t -> Int
- Universum.Container.Class: null :: (Container t, Foldable f, t ~ f a, Element t ~ a) => t -> Bool
+ Universum.Container.Class: null :: (Container t, Foldable f, t ~ f a) => t -> Bool
Files
- CHANGES.md +9/−1
- README.md +12/−11
- benchmark/Main.hs +3/−1
- src/Universum/Base.hs +9/−33
- src/Universum/Bool/Guard.hs +2/−0
- src/Universum/Bool/Reexport.hs +2/−0
- src/Universum/Container.hs +3/−1
- src/Universum/Container/Class.hs +82/−107
- src/Universum/Container/Reexport.hs +2/−0
- src/Universum/Debug.hs +3/−17
- src/Universum/DeepSeq.hs +2/−0
- src/Universum/Exception.hs +4/−15
- src/Universum/Function.hs +2/−0
- src/Universum/Lifted/File.hs +1/−2
- src/Universum/List/Reexport.hs +0/−8
- src/Universum/List/Safe.hs +57/−11
- src/Universum/Monad.hs +1/−1
- src/Universum/Monad/Container.hs +1/−0
- src/Universum/Monad/Maybe.hs +1/−2
- src/Universum/Monad/Reexport.hs +1/−33
- src/Universum/Monoid.hs +1/−6
- src/Universum/Nub.hs +3/−17
- src/Universum/Print/Internal.hs +3/−1
- src/Universum/String.hs +2/−0
- src/Universum/String/Conversion.hs +1/−0
- src/Universum/String/Reexport.hs +2/−0
- src/Universum/TypeOps.hs +3/−13
- src/Universum/Unsafe.hs +8/−4
- src/Universum/VarArg.hs +1/−0
- test/Doctest.hs +0/−11
- test/Spec.hs +3/−1
- universum.cabal +49/−23
CHANGES.md view
@@ -1,5 +1,13 @@-Unreleased+1.7.0 =====++* [#221](https://github.com/serokell/universum/issues/221):+ Add safe versions of `minimum`, `maximum`, `minimumBy`, `maximumBy`, `foldr1`, `foldl1` functions for `NonEmpty` list.+ Old their versions from `Container` typeclass now return `Maybe` and have+ `safe` prefix in name (e.g. `safeMinimum`).+ Add unsafe versions of those functions to `Unsafe` module.+* [#185](https://github.com/serokell/universum/issues/185):+ Enable more warnings, fix all warnings. 1.6.1 =====
README.md view
@@ -1,8 +1,7 @@ Universum ========= -[](https://travis-ci.org/serokell/universum)-[](https://ci.appveyor.com/project/gromakovsky/universum)+[](https://github.com/serokell/universum/actions) [](https://hackage.haskell.org/package/universum) [](http://stackage.org/lts/package/universum) [](http://stackage.org/nightly/package/universum)@@ -16,9 +15,7 @@ documentation regarding internal module structure. 2. `universum`-specific [HLint](http://hackage.haskell.org/package/hlint) rules: [`.hlint.yaml`](https://github.com/serokell/universum/blob/master/.hlint.yaml)-3. Only a few LiquidHaskell properties right now, but LiquidHaskell is on Travis- CI and other properties are just waiting to be added!-4. Focus on safety, convenience and efficiency.+3. Focus on safety, convenience and efficiency. What is this file about? ------------------------@@ -92,8 +89,7 @@ 1. Not trying to be as general as possible (thus we don't export much from [`GHC.Generics`](https://github.com/sdiehl/protolude/blob/41710698eedc66fb0bfc5623d3c3a672421fbab5/src/Protolude.hs#L365)).-2. Not trying to maintain every version of `ghc` compiler (but [at least the- latest 3](https://github.com/serokell/universum/blob/b6353285859e9ed3544bddbf55d70237330ad64a/.travis.yml#L15)).+2. Not trying to maintain every version of `ghc` compiler (but [at least the latest 3](/.github/workflows/ci.yml)). 3. Trying to make writing production code easier (see [enhancements and fixes](https://github.com/serokell/universum/issues)). @@ -134,8 +130,8 @@ Gotchas [↑](#structure-of-this-tutorial) ------- -* `head`, `tail`, `last`, `init` work with `NonEmpty a` instead of `[a]`.-* Safe analogue for `head` function: `safeHead :: [a] -> Maybe a`.+* `head`, `tail`, `last`, `init`, `foldl1`, `minimum` and other were-partial functions work with `NonEmpty a` instead of `[a]`.+* Safe analogue for `head`, `foldl1`, `foldr1`, `minimum`, `maximum` functions, for instance: `safeHead :: [a] -> Maybe a`. * `undefined` triggers a compiler warning, which is probably not what you want. Either use `throwIO`, `Except`, `error` or `bug`. * `map` is `fmap` now. * Multiple sorting functions are available without imports:@@ -147,6 +143,7 @@ `OverloadedStrings` is enabled – it happens because the compiler doesn't know what type to infer for the string. Use `putTextLn` in this case. * Since `show` doesn't come from `Show` anymore, you can't write `Show` instances easily.+See [migration guide](#migration-guide-from-prelude-) for details. * You can't call some `Foldable` methods over `Maybe` and some other types. `Foldable` generalization is useful but [potentially error-prone](https://www.reddit.com/r/haskell/comments/60r9hu/proposal_suggest_explicit_type_application_for/).@@ -289,7 +286,7 @@ * Conversions between `Either` and `Maybe` like `rightToMaybe` and `maybeToLeft` with clear semantic. * `using(Reader|State)[T]` functions as aliases for `flip run(Reader|State)[T]`.-* [`One` type class](https://github.com/serokell/universum/blob/master/src/Containers.hs#L473)+* [`One` type class](/src/Universum/Container/Class.hs) for creating singleton containers. Even monomorhpic ones like `Text`. * `evaluateWHNF` and `evaluateNF` functions as clearer and lifted aliases for `evaluate` and `evaluate . force`.@@ -304,7 +301,7 @@ This section describes what you need to change to make your code compile with `universum`. 1. Enable `-XOverloadedStrings` and `-XTypeFamilies` extension by default for your project.-2. Since `head`, `tail`, `last` and `init` work for `NonEmpty` you should+2. Since `head`, `tail`, `minimum` and some other functions work for `NonEmpty` you should refactor your code in one of the multiple ways described below: 1. Change `[a]` to `NonEmpty a` where it makes sense. 2. Use functions which return `Maybe`. They can be implemented using `nonEmpty` function. Like `head <$> nonEmpty l`.@@ -345,6 +342,10 @@ + Use `toText/toLText/toString` functions to convert to `Text/LazyText/String` types. + Use `encodeUtf8/decodeUtf8` to convert to/from `ByteString`. 8. Run `hlint` using `.hlint.yaml` file from `universum` package to cleanup code and imports.+9. Since vanilla `show` from the `Show` class is not available, your custom `Show` instances will fail to compile.+You can `import qualified Text.Show` to bring vanilla `show` to scope with qualified name.+It will not conflict with `show` from `universum` and your `Show` instances will compile successfully.+ Projects that use Universum [↑](#structure-of-this-tutorial) ---------------------------
benchmark/Main.hs view
@@ -1,4 +1,6 @@-module Main where+module Main+ ( main+ ) where import Universum hiding (show)
src/Universum/Base.hs view
@@ -1,9 +1,7 @@ {-# LANGUAGE BangPatterns #-}-{-# LANGUAGE CPP #-} {-# LANGUAGE Unsafe #-} --- | Reexports from @GHC.*@ modules of <https://www.stackage.org/lts-8.9/package/base-4.9.1.0 base>--- package.+-- | Reexports from @GHC.*@ modules of the <https://hackage.haskell.org/package/base> package. module Universum.Base ( -- * Base types@@ -35,22 +33,15 @@ , module GHC.Num , module GHC.Real , module GHC.Show--#if MIN_VERSION_base(4,10,0) , module GHC.TypeNats-#else- , module GHC.TypeLits-#endif , module GHC.Types--#if ( __GLASGOW_HASKELL__ >= 800 ) , module GHC.OverloadedLabels , module GHC.ExecutionStack , module GHC.Stack -- * Data.Kind+ , Constraint , Type-#endif , ($!) ) where@@ -67,45 +58,30 @@ -- Base typeclasses import Data.Eq (Eq (..))-import Data.Foldable (Foldable, concat, concatMap, foldlM, foldrM, maximumBy, minimumBy)+import Data.Foldable (Foldable, concat, concatMap, foldlM, foldrM)+import Data.Kind (Constraint, Type) import Data.Ord (Down (..), Ord (..), Ordering (..), comparing) import Data.Traversable (Traversable (..), fmapDefault, foldMapDefault, forM, mapAccumL, mapAccumR) -- Base GHC types-#if ( __GLASGOW_HASKELL__ >= 710 ) import Data.Proxy (Proxy (..)) import Data.Typeable (Typeable) import Data.Void (Void, absurd, vacuous)-#endif import GHC.Base (String, asTypeOf, maxInt, minInt, ord, seq) import GHC.Enum (Bounded (..), Enum (..), boundedEnumFrom, boundedEnumFromThen)-import GHC.Exts (Constraint, FunPtr, Ptr)+import GHC.ExecutionStack (getStackTrace, showStackTrace)+import GHC.Exts (FunPtr, Ptr) import GHC.Float (Double (..), Float (..), Floating (acos, acosh, asin, asinh, atan, atanh, cos, cosh, exp, logBase, pi, sin, sinh, sqrt, tan, tanh, (**))) import GHC.Generics (Generic) import GHC.Num (Integer, Num (..), subtract)+import GHC.OverloadedLabels (IsLabel (..)) import GHC.Real hiding (showSigned, (%)) import GHC.Show (Show)-#if MIN_VERSION_base(4,10,0)-import GHC.TypeNats (CmpNat, KnownNat, Nat, SomeNat (..), natVal, someNatVal)-#else-import GHC.TypeLits (CmpNat, KnownNat, Nat, SomeNat (..), natVal, someNatVal)-#endif--import GHC.Types (Bool, Char, Coercible, IO, Int, Ordering, Word)---#if ( __GLASGOW_HASKELL__ >= 800 )-import GHC.ExecutionStack (getStackTrace, showStackTrace)-import GHC.OverloadedLabels (IsLabel (..)) import GHC.Stack (CallStack, HasCallStack, callStack, currentCallStack, getCallStack, prettyCallStack, prettySrcLoc, withFrozenCallStack)-#endif--#if ( __GLASGOW_HASKELL__ >= 800 )--- TODO: move Constraint here later-import Data.Kind (Type)-#endif+import GHC.TypeNats (CmpNat, KnownNat, Nat, SomeNat (..), natVal, someNatVal)+import GHC.Types (Bool, Char, Coercible, IO, Int, Ordering, Word) -- $setup -- >>> import Universum.Function (const, ($))
src/Universum/Bool/Guard.hs view
@@ -1,3 +1,5 @@+{-# LANGUAGE Safe #-}+ -- | This module contains monadic predicates. module Universum.Bool.Guard
src/Universum/Bool/Reexport.hs view
@@ -1,3 +1,5 @@+{-# LANGUAGE Safe #-}+ -- | This module reexports functions to work with 'Bool' type. module Universum.Bool.Reexport
src/Universum/Container.hs view
@@ -1,3 +1,5 @@+{-# LANGUAGE Safe #-}+ -- | This module exports all container-related stuff. module Universum.Container@@ -5,5 +7,5 @@ , module Universum.Container.Reexport ) where -import Universum.Container.Class+import Universum.Container.Class hiding (checkingNotNull) import Universum.Container.Reexport
src/Universum/Container/Class.hs view
@@ -23,6 +23,7 @@ ( -- * Foldable-like classes and methods ToPairs (..) , Container (..)+ , checkingNotNull , flipfoldl' @@ -42,6 +43,7 @@ ) where import Data.Coerce (Coercible, coerce)+import Data.Kind (Type) import Prelude hiding (all, and, any, elem, foldMap, foldl, foldr, mapM_, notElem, null, or, print, product, sequence_, sum) @@ -50,18 +52,12 @@ import Universum.Container.Reexport (HashMap, HashSet, Hashable, IntMap, IntSet, Map, Seq, Set, Vector) import Universum.Functor (Identity)-import Universum.Monad.Reexport (fromMaybe) import Universum.Monoid (All (..), Any (..), Dual, First (..), Last, Product, Sum) -#if __GLASGOW_HASKELL__ >= 800-import GHC.Err (errorWithoutStackTrace) import GHC.TypeLits (ErrorMessage (..), Symbol, TypeError)-#endif -#if ( __GLASGOW_HASKELL__ >= 800 ) import qualified Data.List.NonEmpty as NE import Universum.List.Reexport (NonEmpty)-#endif import qualified Data.Foldable as Foldable @@ -111,9 +107,9 @@ class ToPairs t where {-# MINIMAL toPairs #-} -- | Type of keys of the mapping.- type Key t :: *+ type Key t :: Type -- | Type of value of the mapping.- type Val t :: *+ type Val t :: Type -- | Converts the structure to the list of the key-value pairs. -- >>> toPairs (HashMap.fromList [('a', "xxx"), ('b', "yyy")])@@ -173,8 +169,8 @@ ---------------------------------------------------------------------------- -- | Default implementation of 'Element' associated type family.-type family ElementDefault (t :: *) :: * where- ElementDefault (f a) = a+type family ElementDefault (t :: Type) :: Type where+ ElementDefault (_ a) = a -- | Very similar to 'Foldable' but also allows instances for monomorphic types -- like 'Text' but forbids instances for 'Maybe' and similar. This class is used as@@ -195,7 +191,7 @@ -- so we can't implement nice interface using old higher-kinded types -- approach. Implementing this as an associated type family instead of -- top-level family gives you more control over element types.- type Element t :: *+ type Element t :: Type type Element t = ElementDefault t -- | Convert container to list of elements.@@ -216,7 +212,7 @@ -- >>> null @Text "aba" -- False null :: t -> Bool- default null :: (Foldable f, t ~ f a, Element t ~ a) => t -> Bool+ default null :: (Foldable f, t ~ f a) => t -> Bool null = Foldable.null {-# INLINE null #-} @@ -236,7 +232,7 @@ {-# INLINE foldl' #-} length :: t -> Int- default length :: (Foldable f, t ~ f a, Element t ~ a) => t -> Int+ default length :: (Foldable f, t ~ f a) => t -> Int length = Foldable.length {-# INLINE length #-} @@ -249,16 +245,6 @@ elem = Foldable.elem {-# INLINE elem #-} - maximum :: Ord (Element t) => t -> Element t- default maximum :: (Foldable f, t ~ f a, Element t ~ a, Ord (Element t)) => t -> Element t- maximum = Foldable.maximum- {-# INLINE maximum #-}-- minimum :: Ord (Element t) => t -> Element t- default minimum :: (Foldable f, t ~ f a, Element t ~ a, Ord (Element t)) => t -> Element t- minimum = Foldable.minimum- {-# INLINE minimum #-}- foldMap :: Monoid m => (Element t -> m) -> t -> m foldMap f = foldr (mappend . f) mempty {-# INLINE foldMap #-}@@ -272,36 +258,6 @@ where f' k x z = k $! f x z {-# INLINE foldr' #-} - foldr1 :: (Element t -> Element t -> Element t) -> t -> Element t- foldr1 f xs =-#if __GLASGOW_HASKELL__ >= 800- fromMaybe (errorWithoutStackTrace "foldr1: empty structure")- (foldr mf Nothing xs)-#else- fromMaybe (error "foldr1: empty structure")- (foldr mf Nothing xs)-#endif- where- mf x m = Just (case m of- Nothing -> x- Just y -> f x y)- {-# INLINE foldr1 #-}-- foldl1 :: (Element t -> Element t -> Element t) -> t -> Element t- foldl1 f xs =-#if __GLASGOW_HASKELL__ >= 800- fromMaybe (errorWithoutStackTrace "foldl1: empty structure")- (foldl mf Nothing xs)-#else- fromMaybe (error "foldl1: empty structure")- (foldl mf Nothing xs)-#endif- where- mf m y = Just (case m of- Nothing -> y- Just x -> f x y)- {-# INLINE foldl1 #-}- notElem :: Eq (Element t) => Element t -> t -> Bool notElem x = not . elem x {-# INLINE notElem #-}@@ -328,6 +284,43 @@ safeHead = foldr (\x _ -> Just x) Nothing {-# INLINE safeHead #-} + safeMaximum :: Ord (Element t) => t -> Maybe (Element t)+ default safeMaximum+ :: (Foldable f, t ~ f a, Element t ~ a, Ord (Element t))+ => t -> Maybe (Element t)+ safeMaximum = checkingNotNull Foldable.maximum+ {-# INLINE safeMaximum #-}++ safeMinimum :: Ord (Element t) => t -> Maybe (Element t)+ default safeMinimum+ :: (Foldable f, t ~ f a, Element t ~ a, Ord (Element t))+ => t -> Maybe (Element t)+ safeMinimum = checkingNotNull Foldable.minimum+ {-# INLINE safeMinimum #-}++ safeFoldr1 :: (Element t -> Element t -> Element t) -> t -> Maybe (Element t)+ safeFoldr1 f xs = foldr mf Nothing xs+ where+ mf x m = Just (case m of+ Nothing -> x+ Just y -> f x y)+ {-# INLINE safeFoldr1 #-}++ safeFoldl1 :: (Element t -> Element t -> Element t) -> t -> Maybe (Element t)+ safeFoldl1 f xs = foldl mf Nothing xs+ where+ mf m y = Just (case m of+ Nothing -> y+ Just x -> f x y)+ {-# INLINE safeFoldl1 #-}++-- | Helper for lifting operations which require container to be not empty.+checkingNotNull :: Container t => (t -> Element t) -> t -> Maybe (Element t)+checkingNotNull f t+ | null t = Nothing+ | otherwise = Just $ f t+{-# INLINE checkingNotNull #-}+ ---------------------------------------------------------------------------- -- Instances for monomorphic containers ----------------------------------------------------------------------------@@ -344,18 +337,18 @@ {-# INLINE foldl #-} foldl' = T.foldl' {-# INLINE foldl' #-}- foldr1 = T.foldr1- {-# INLINE foldr1 #-}- foldl1 = T.foldl1- {-# INLINE foldl1 #-}+ safeFoldr1 f = checkingNotNull (T.foldr1 f)+ {-# INLINE safeFoldr1 #-}+ safeFoldl1 f = checkingNotNull (T.foldl1 f)+ {-# INLINE safeFoldl1 #-} length = T.length {-# INLINE length #-} elem c = T.isInfixOf (T.singleton c) -- there are rewrite rules for this {-# INLINE elem #-}- maximum = T.maximum- {-# INLINE maximum #-}- minimum = T.minimum- {-# INLINE minimum #-}+ safeMaximum = checkingNotNull T.maximum+ {-# INLINE safeMaximum #-}+ safeMinimum = checkingNotNull T.minimum+ {-# INLINE safeMinimum #-} all = T.all {-# INLINE all #-} any = T.any@@ -377,19 +370,19 @@ {-# INLINE foldl #-} foldl' = TL.foldl' {-# INLINE foldl' #-}- foldr1 = TL.foldr1- {-# INLINE foldr1 #-}- foldl1 = TL.foldl1- {-# INLINE foldl1 #-}+ safeFoldr1 f = checkingNotNull (TL.foldr1 f)+ {-# INLINE safeFoldr1 #-}+ safeFoldl1 f = checkingNotNull (TL.foldl1 f)+ {-# INLINE safeFoldl1 #-} length = fromIntegral . TL.length {-# INLINE length #-} -- will be okay thanks to rewrite rules elem c s = TL.isInfixOf (TL.singleton c) s {-# INLINE elem #-}- maximum = TL.maximum- {-# INLINE maximum #-}- minimum = TL.minimum- {-# INLINE minimum #-}+ safeMaximum = checkingNotNull TL.maximum+ {-# INLINE safeMaximum #-}+ safeMinimum = checkingNotNull TL.minimum+ {-# INLINE safeMinimum #-} all = TL.all {-# INLINE all #-} any = TL.any@@ -411,20 +404,20 @@ {-# INLINE foldl #-} foldl' = BS.foldl' {-# INLINE foldl' #-}- foldr1 = BS.foldr1- {-# INLINE foldr1 #-}- foldl1 = BS.foldl1- {-# INLINE foldl1 #-}+ safeFoldr1 f = checkingNotNull (BS.foldr1 f)+ {-# INLINE safeFoldr1 #-}+ safeFoldl1 f = checkingNotNull (BS.foldl1 f)+ {-# INLINE safeFoldl1 #-} length = BS.length {-# INLINE length #-} elem = BS.elem {-# INLINE elem #-} notElem = BS.notElem {-# INLINE notElem #-}- maximum = BS.maximum- {-# INLINE maximum #-}- minimum = BS.minimum- {-# INLINE minimum #-}+ safeMaximum = checkingNotNull BS.maximum+ {-# INLINE safeMaximum #-}+ safeMinimum = checkingNotNull BS.minimum+ {-# INLINE safeMinimum #-} all = BS.all {-# INLINE all #-} any = BS.any@@ -446,20 +439,20 @@ {-# INLINE foldl #-} foldl' = BSL.foldl' {-# INLINE foldl' #-}- foldr1 = BSL.foldr1- {-# INLINE foldr1 #-}- foldl1 = BSL.foldl1- {-# INLINE foldl1 #-}+ safeFoldr1 f = checkingNotNull (BSL.foldr1 f)+ {-# INLINE safeFoldr1 #-}+ safeFoldl1 f = checkingNotNull (BSL.foldl1 f)+ {-# INLINE safeFoldl1 #-} length = fromIntegral . BSL.length {-# INLINE length #-} elem = BSL.elem {-# INLINE elem #-} notElem = BSL.notElem {-# INLINE notElem #-}- maximum = BSL.maximum- {-# INLINE maximum #-}- minimum = BSL.minimum- {-# INLINE minimum #-}+ safeMaximum = checkingNotNull BSL.maximum+ {-# INLINE safeMaximum #-}+ safeMinimum = checkingNotNull BSL.minimum+ {-# INLINE safeMinimum #-} all = BSL.all {-# INLINE all #-} any = BSL.any@@ -485,10 +478,10 @@ {-# INLINE length #-} elem = IS.member {-# INLINE elem #-}- maximum = IS.findMax- {-# INLINE maximum #-}- minimum = IS.findMin- {-# INLINE minimum #-}+ safeMaximum = checkingNotNull IS.findMax+ {-# INLINE safeMaximum #-}+ safeMinimum = checkingNotNull IS.findMin+ {-# INLINE safeMinimum #-} safeHead = fmap fst . IS.minView {-# INLINE safeHead #-} @@ -514,7 +507,6 @@ instance Container [a] instance Container (Const a b) -#if __GLASGOW_HASKELL__ >= 800 -- Algebraic types instance Container (Dual a) instance Container (First a)@@ -523,7 +515,6 @@ instance Container (Sum a) instance Container (NonEmpty a) instance Container (ZipList a)-#endif -- Containers instance Container (HashMap k v)@@ -548,7 +539,6 @@ flipfoldl' f = foldl' (flip f) {-# INLINE flipfoldl' #-} -#if MIN_VERSION_base(4,10,1) -- | Stricter version of 'Prelude.sum'. -- -- >>> sum [1..10]@@ -568,11 +558,9 @@ -- use -- maybeToMonoid :: Monoid m => Maybe m -> m -- ...-#endif sum :: (Container t, Num (Element t)) => t -> Element t sum = foldl' (+) 0 -#if MIN_VERSION_base(4,10,1) -- | Stricter version of 'Prelude.product'. -- -- >>> product [1..10]@@ -592,7 +580,6 @@ -- use -- maybeToMonoid :: Monoid m => Maybe m -> m -- ...-#endif product :: (Container t, Num (Element t)) => t -> Element t product = foldl' (*) 1 @@ -686,7 +673,6 @@ -- Disallowed instances ---------------------------------------------------------------------------- -#if __GLASGOW_HASKELL__ >= 800 type family DisallowInstance (z :: Symbol) :: ErrorMessage where DisallowInstance z = Text "Do not use 'Foldable' methods on " :<>: Text z :$$: Text "Suggestions:"@@ -701,20 +687,11 @@ :$$: Text " use" :$$: Text " maybeToMonoid :: Monoid m => Maybe m -> m" :$$: Text ""-#endif -#if __GLASGOW_HASKELL__ >= 800 instance TypeError (DisallowInstance "tuple") => Container (a, b) instance TypeError (DisallowInstance "Maybe") => Container (Maybe a) instance TypeError (DisallowInstance "Either") => Container (Either a b) instance TypeError (DisallowInstance "Identity") => Container (Identity a)-#else-class ForbiddenFoldable a-instance ForbiddenFoldable (a, b) => Container (a, b)-instance ForbiddenFoldable (Maybe a) => Container (Maybe a)-instance ForbiddenFoldable (Either a b) => Container (Either a b)-instance ForbiddenFoldable (Identity a) => Container (Identity a)-#endif ---------------------------------------------------------------------------- -- One@@ -742,12 +719,10 @@ one = (:[]) {-# INLINE one #-} -#if ( __GLASGOW_HASKELL__ >= 800 ) instance One (NE.NonEmpty a) where type OneItem (NE.NonEmpty a) = a one = (NE.:|[]) {-# INLINE one #-}-#endif instance One (SEQ.Seq a) where type OneItem (SEQ.Seq a) = a
src/Universum/Container/Reexport.hs view
@@ -1,3 +1,5 @@+{-# LANGUAGE Trustworthy #-}+ -- | This module reexports all container related stuff from 'Prelude'. module Universum.Container.Reexport
src/Universum/Debug.hs view
@@ -1,15 +1,14 @@ {-# LANGUAGE CPP #-} {-# LANGUAGE DeriveDataTypeable #-} {-# LANGUAGE DeriveGeneric #-}+{-# LANGUAGE DerivingStrategies #-} {-# LANGUAGE ImplicitParams #-} {-# LANGUAGE KindSignatures #-} {-# LANGUAGE MagicHash #-} {-# LANGUAGE PolyKinds #-} {-# LANGUAGE RankNTypes #-} {-# LANGUAGE Trustworthy #-}-#if ( __GLASGOW_HASKELL__ >= 804 ) {-# LANGUAGE TypeInType #-}-#endif -- | Functions for debugging. If you left these functions in your code -- then warning is generated to remind you about left usages. Also, some@@ -32,18 +31,14 @@ import Control.Monad (Monad, return) import Data.Data (Data) import Data.Text (Text, pack, unpack)-import Data.Typeable (Typeable) import GHC.Generics (Generic) import System.IO.Unsafe (unsafePerformIO) -#if ( __GLASGOW_HASKELL__ >= 800 ) import GHC.Exception (errorCallWithCallStackException) import GHC.Exts (RuntimeRep, TYPE, raise#) -import Universum.Base (HasCallStack, callStack)-#endif- import Universum.Applicative (pass)+import Universum.Base (HasCallStack, callStack) import Universum.Print (putStrLn) import qualified Prelude as P@@ -56,14 +51,9 @@ return expr) -- | 'P.error' that takes 'Text' as an argument.-#if ( __GLASGOW_HASKELL__ >= 800 ) error :: forall (r :: RuntimeRep) . forall (a :: TYPE r) . HasCallStack => Text -> a error s = raise# (errorCallWithCallStackException (unpack s) callStack)-#else-error :: Text -> a-error s = P.error (unpack s)-#endif -- | Version of 'Debug.Trace.traceShow' that leaves a warning. {-# WARNING traceShow "'traceShow' remains in code" #-}@@ -120,13 +110,9 @@ -- | Similar to 'undefined' but data type. {-# WARNING Undefined "'Undefined' type remains in code" #-} data Undefined = Undefined- deriving (P.Eq, P.Ord, P.Show, P.Read, P.Enum, P.Bounded, Data, Typeable, Generic)+ deriving stock (P.Eq, P.Ord, P.Show, P.Read, P.Enum, P.Bounded, Data, Generic) -- | 'P.undefined' that leaves a warning in code on every usage. {-# WARNING undefined "'undefined' function remains in code (or use 'error')" #-}-#if ( __GLASGOW_HASKELL__ >= 800 ) undefined :: forall (r :: RuntimeRep) . forall (a :: TYPE r) . HasCallStack => a-#else-undefined :: a-#endif undefined = P.undefined
src/Universum/DeepSeq.hs view
@@ -1,3 +1,5 @@+{-# LANGUAGE Trustworthy #-}+ -- | This module contains useful functions to evaluate expressions to weak-head -- normal form or just normal form. Useful to force traces or @error@ inside -- monadic computation or to remove space leaks.
src/Universum/Exception.hs view
@@ -1,4 +1,4 @@-{-# LANGUAGE CPP #-}+{-# LANGUAGE DerivingStrategies #-} {-# LANGUAGE MultiParamTypeClasses #-} {-# LANGUAGE PatternSynonyms #-} {-# LANGUAGE Safe #-}@@ -9,24 +9,21 @@ module Universum.Exception ( module Control.Exception.Safe-#if ( __GLASGOW_HASKELL__ >= 800 ) , Bug (..) , bug , pattern Exc-#endif , note ) where -- exceptions from safe-exceptions import Control.Exception.Safe (Exception (..), MonadCatch, MonadMask (..), MonadThrow, SomeException (..), bracket, bracketOnError, bracket_, catch,- catchAny, displayException, finally, handleAny, onException,- throwM, try, tryAny)+ catchAny, displayException, finally, handleAny, onException, throwM,+ try, tryAny) import Control.Monad.Except (MonadError, throwError) import Universum.Applicative (Applicative (pure)) import Universum.Monad (Maybe (..), maybe) -#if ( __GLASGOW_HASKELL__ >= 800 ) import Data.List ((++)) import GHC.Show (Show) import GHC.Stack (CallStack, HasCallStack, callStack, prettyCallStack)@@ -36,7 +33,7 @@ -- | Type that represents exceptions used in cases when a particular codepath -- is not meant to be ever executed, but happens to be executed anyway. data Bug = Bug SomeException CallStack- deriving (Show)+ deriving stock (Show) instance Exception Bug where displayException (Bug e cStack) = Safe.displayException e ++ "\n"@@ -46,21 +43,14 @@ -- throw the exception wrapped into 'Bug' data type. bug :: (HasCallStack, Exception e) => e -> a bug e = Safe.impureThrow (Bug (Safe.toException e) callStack)-#endif -- To suppress redundant applicative constraint warning on GHC 8.0 -- | Throws error for 'Maybe' if 'Data.Maybe.Nothing' is given. -- Operates over 'MonadError'.-#if ( __GLASGOW_HASKELL__ >= 800 ) note :: (MonadError e m) => e -> Maybe a -> m a note err = maybe (throwError err) pure-#else-note :: (MonadError e m, Applicative m) => e -> Maybe a -> m a-note err = maybe (throwError err) pure-#endif -#if ( __GLASGOW_HASKELL__ >= 800 ) {- | Pattern synonym to easy pattern matching on exceptions. So intead of writing something like this: @@ -86,4 +76,3 @@ pattern Exc e <- (fromException -> Just e) where Exc e = toException e-#endif
src/Universum/Function.hs view
@@ -1,3 +1,5 @@+{-# LANGUAGE Safe #-}+ -- | This module reexports very basic and primitive functions and function combinators. module Universum.Function
src/Universum/Lifted/File.hs view
@@ -1,4 +1,3 @@-{-# LANGUAGE CPP #-} {-# LANGUAGE Safe #-} -- | Lifted versions of functions working with files and common IO.@@ -22,7 +21,7 @@ import System.IO (Handle, IOMode) import qualified Data.Text.IO as XIO-import qualified System.IO as XIO (openFile, hClose, IO)+import qualified System.IO as XIO (IO, hClose, openFile) ---------------------------------------------------------------------------- -- Text
src/Universum/List/Reexport.hs view
@@ -1,15 +1,10 @@-{-# LANGUAGE CPP #-} {-# LANGUAGE Trustworthy #-} -- | This module reexports functinons to work with list, 'NonEmpty' and String types. module Universum.List.Reexport ( module Data.List--#if ( __GLASGOW_HASKELL__ >= 800 ) , module Data.List.NonEmpty-#endif- , module GHC.Exts ) where @@ -18,9 +13,6 @@ intersperse, isPrefixOf, iterate, permutations, repeat, replicate, reverse, scanl, scanr, sort, sortBy, sortOn, splitAt, subsequences, tails, take, takeWhile, transpose, unfoldr, unzip, unzip3, zip, zip3, zipWith, (++))--#if ( __GLASGOW_HASKELL__ >= 800 ) import Data.List.NonEmpty (NonEmpty (..), head, init, last, nonEmpty, tail)-#endif import GHC.Exts (sortWith)
src/Universum/List/Safe.hs view
@@ -1,27 +1,29 @@-{-# LANGUAGE CPP #-} {-# LANGUAGE Safe #-} -- | This module contains safe functions to work with list type (mostly with 'NonEmpty'). module Universum.List.Safe ( uncons-#if ( __GLASGOW_HASKELL__ >= 800 ) , whenNotNull , whenNotNullM-#endif+ , foldr1+ , foldl1+ , minimum+ , maximum+ , minimumBy+ , maximumBy ) where -#if ( __GLASGOW_HASKELL__ >= 800 )+import qualified Data.Foldable as F+import Data.Ord (Ord, Ordering)+ import Universum.Applicative (Applicative, pass) import Universum.List.Reexport (NonEmpty (..))-import Universum.Monad (Monad (..))-#endif--import Universum.Monad (Maybe (..))+import Universum.Monad (Maybe (..), Monad (..)) -- $setup -- >>> import Universum.Applicative (pure)--- >>> import Universum.Base ((==), even)+-- >>> import Universum.Base ((==), (+), even) -- >>> import Universum.Bool (Bool (..), not) -- >>> import Universum.Container (length) -- >>> import Universum.Function (($))@@ -39,7 +41,6 @@ uncons [] = Nothing uncons (x:xs) = Just (x, xs) -#if ( __GLASGOW_HASKELL__ >= 800 ) {- | Performs given action over 'NonEmpty' list if given list is non empty. >>> whenNotNull [] $ \(b :| _) -> print (not b)@@ -56,4 +57,49 @@ whenNotNullM :: Monad m => m [a] -> (NonEmpty a -> m ()) -> m () whenNotNullM ml f = ml >>= \l -> whenNotNull l f {-# INLINE whenNotNullM #-}-#endif++-- | A variant of 'foldl' that has no base case, and thus may only be+-- applied to 'NonEmpty'.+--+-- >>> foldl1 (+) (1 :| [2,3,4,5])+-- 15+foldl1 :: (a -> a -> a) -> NonEmpty a -> a+foldl1 = F.foldl1+{-# INLINE foldl1 #-}++-- | A variant of 'foldr' that has no base case, and thus may only be+-- applied to 'NonEmpty'.+--+-- >>> foldr1 (+) (1 :| [2,3,4,5])+-- 15+foldr1 :: (a -> a -> a) -> NonEmpty a -> a+foldr1 = F.foldr1+{-# INLINE foldr1 #-}++-- | The least element of a 'NonEmpty' with respect to the given+-- comparison function.+minimumBy :: (a -> a -> Ordering) -> NonEmpty a -> a+minimumBy = F.minimumBy+{-# INLINE minimumBy #-}++-- | The least element of a 'NonEmpty'.+--+-- >>> minimum (1 :| [2,3,4,5])+-- 1+minimum :: Ord a => NonEmpty a -> a+minimum = F.minimum+{-# INLINE minimum #-}++-- | The largest element of a 'NonEmpty' with respect to the given+-- comparison function.+maximumBy :: (a -> a -> Ordering) -> NonEmpty a -> a+maximumBy = F.maximumBy+{-# INLINE maximumBy #-}++-- | The largest element of a 'NonEmpty'.+--+-- >>> maximum (1 :| [2,3,4,5])+-- 5+maximum :: Ord a => NonEmpty a -> a+maximum = F.maximum+{-# INLINE maximum #-}
src/Universum/Monad.hs view
@@ -1,4 +1,4 @@-{-# LANGUAGE Trustworthy #-}+{-# LANGUAGE Safe #-} -- | Reexporting useful monadic stuff.
src/Universum/Monad/Container.hs view
@@ -1,3 +1,4 @@+{-# LANGUAGE Trustworthy #-} {-# LANGUAGE TypeFamilies #-} -- | This module exports functions which allow to process instances of
src/Universum/Monad/Maybe.hs view
@@ -13,8 +13,7 @@ ) where import Universum.Applicative (Applicative, pass, pure)-import Universum.Monad.Reexport (fromMaybe)-import Universum.Monad.Reexport (Maybe (..), Monad (..))+import Universum.Monad.Reexport (Maybe (..), Monad (..), fromMaybe) -- $setup -- >>> import Universum.Bool (Bool (..), not)
src/Universum/Monad/Reexport.hs view
@@ -1,5 +1,4 @@-{-# LANGUAGE CPP #-}-{-# LANGUAGE Trustworthy #-}+{-# LANGUAGE Safe #-} -- | This module reexports functions to work with monads. @@ -65,35 +64,4 @@ import Data.Either (Either (..), either, isLeft, isRight, lefts, partitionEithers, rights) import Control.Monad hiding (fail)--#if __GLASGOW_HASKELL__ >= 800 import Control.Monad.Fail (MonadFail (..))-#else-import Prelude (String)-import Text.ParserCombinators.ReadP (ReadP)-import Text.ParserCombinators.ReadPrec (ReadPrec)--import Universum.Base (IO)--import qualified Prelude as P (fail)---- | Class for 'Monad's that can 'fail'.--- Copied from 'fail' by Herbert Valerio Riedel (the library is under BSD3).-class Monad m => MonadFail m where- fail :: String -> m a--instance MonadFail Maybe where- fail _ = Nothing--instance MonadFail [] where- fail _ = []--instance MonadFail IO where- fail = P.fail--instance MonadFail ReadPrec where- fail = P.fail -- = P (\_ -> fail s)--instance MonadFail ReadP where- fail = P.fail-#endif
src/Universum/Monoid.hs view
@@ -1,22 +1,17 @@-{-# LANGUAGE CPP #-}+{-# LANGUAGE Safe #-} -- | This module reexports functions to work with monoids plus adds extra useful functions. module Universum.Monoid ( module Data.Monoid-#if ( __GLASGOW_HASKELL__ >= 800 ) , module Data.Semigroup-#endif , maybeToMonoid ) where import Data.Monoid (All (..), Alt (..), Any (..), Dual (..), Endo (..), First (..), Last (..), Monoid (..), Product (..), Sum (..))--#if ( __GLASGOW_HASKELL__ >= 800 ) import Data.Semigroup (Option (..), Semigroup (sconcat, stimes, (<>)), WrappedMonoid, cycle1, mtimesDefault, stimesIdempotent, stimesIdempotentMonoid, stimesMonoid)-#endif import Universum.Monad.Reexport (Maybe, fromMaybe)
src/Universum/Nub.hs view
@@ -1,3 +1,5 @@+{-# LANGUAGE Safe #-}+ {-| Functions to remove duplicates from a list. = Performance@@ -32,25 +34,10 @@ import Data.Hashable (Hashable) import Data.HashSet as HashSet import Data.Ord (Ord)-import Prelude (Bool, Char, (.))+import Prelude ((.)) import qualified Data.Set as Set --- Liquid Haskell check for duplicates.-{-@ type ListUnique a = {v : [a] | NoDups v} @-}--{-@ predicate NoDups L = Set_emp (dups L) @-}--{-@ measure dups :: [a] -> (Set.Set a)- dups ([]) = {v | Set_emp v}- dups (x:xs) = {v | v =- if (Set_mem x (listElts xs))- then (Set_cup (Set_sng x) (dups xs))- else (dups xs)}-@-}--{-@ Set.toList :: Set.Set a -> ListUnique a @-}- -- | Like 'Prelude.nub' but runs in @O(n * log n)@ time and requires 'Ord'. -- -- >>> ordNub [3, 3, 3, 2, 2, -1, 1]@@ -81,7 +68,6 @@ -- -- >>> sortNub [3, 3, 3, 2, 2, -1, 1] -- [-1,1,2,3]-{-@ sortNub :: [a] -> ListUnique a @-} sortNub :: (Ord a) => [a] -> [a] sortNub = Set.toList . Set.fromList
src/Universum/Print/Internal.hs view
@@ -12,9 +12,11 @@ __even for minor version increments__. -} {-# LANGUAGE FlexibleInstances #-}+{-# LANGUAGE Trustworthy #-}+ module Universum.Print.Internal (Print(..)) where -import qualified System.IO as SIO (hPutStr, hPutStrLn, Handle)+import qualified System.IO as SIO (Handle, hPutStr, hPutStrLn) import qualified Data.ByteString.Char8 as BS import qualified Data.ByteString.Lazy.Char8 as BL
src/Universum/String.hs view
@@ -1,3 +1,5 @@+{-# LANGUAGE Safe #-}+ -- | Type classes for convertion between different string representations. module Universum.String
src/Universum/String/Conversion.hs view
@@ -2,6 +2,7 @@ {-# LANGUAGE ExplicitForAll #-} {-# LANGUAGE FlexibleInstances #-} {-# LANGUAGE MultiParamTypeClasses #-}+{-# LANGUAGE Trustworthy #-} {-# LANGUAGE TypeSynonymInstances #-} {-# OPTIONS_GHC -Wno-orphans #-}
src/Universum/String/Reexport.hs view
@@ -1,3 +1,5 @@+{-# LANGUAGE Safe #-}+ -- | This module reexports functions to work with 'Text' and 'ByteString' types. module Universum.String.Reexport
src/Universum/TypeOps.hs view
@@ -1,19 +1,13 @@-{-# LANGUAGE CPP #-} {-# LANGUAGE ConstraintKinds #-} {-# LANGUAGE DataKinds #-} {-# LANGUAGE ExplicitNamespaces #-} {-# LANGUAGE KindSignatures #-} {-# LANGUAGE NoImplicitPrelude #-} {-# LANGUAGE PolyKinds #-}+{-# LANGUAGE Safe #-} {-# LANGUAGE TypeFamilies #-} {-# LANGUAGE TypeOperators #-} -#if __GLASGOW_HASKELL__ <= 710-{-# LANGUAGE Trustworthy #-}-#else-{-# LANGUAGE Safe #-}-#endif- -- | Type operators for writing convenient type signatures. module Universum.TypeOps@@ -22,11 +16,7 @@ , type ($) ) where -#if __GLASGOW_HASKELL__ <= 710-import GHC.Prim (Constraint)-#else import Data.Kind (Constraint)-#endif -- | Infix application. --@@ -46,7 +36,7 @@ -- a :: (Show a, Read a) => a -> a -- @ type family (<+>) (c :: [k -> Constraint]) (a :: k) where- (<+>) '[] a = (() :: Constraint)+ (<+>) '[] _ = (() :: Constraint) (<+>) (ch ': ct) a = (ch a, (<+>) ct a) infixl 9 <+> @@ -65,7 +55,7 @@ -- f :: Each '[Show] [a, b] => a -> b -> String -- @ type family Each (c :: [k -> Constraint]) (as :: [k]) where- Each c '[] = (() :: Constraint)+ Each _ '[] = (() :: Constraint) Each c (h ': t) = (c <+> h, Each c t) -- | Map several constraints over a single variable.
src/Universum/Unsafe.hs view
@@ -22,15 +22,19 @@ , at , (!!) , fromJust+ , foldr1+ , foldl1+ , minimum+ , maximum+ , minimumBy+ , maximumBy ) where -import Data.List (head, init, last, tail, (!!))+import Data.List (foldl1, foldr1, head, init, last, maximum, maximumBy, minimum, minimumBy, tail,+ (!!)) import Data.Maybe (fromJust) import Universum.Base (Int)---- Non empty list definition for @liquidhaskell@.-{-@ type NonEmptyList a = {xs : [a] | len xs > 0} @-} -- | Similar to '!!' but with flipped arguments. {-@ at :: n : Nat -> {xs : NonEmptyList a | len xs > n} -> a @-}
src/Universum/VarArg.hs view
@@ -2,6 +2,7 @@ {-# LANGUAGE FunctionalDependencies #-} {-# LANGUAGE IncoherentInstances #-} {-# LANGUAGE MultiParamTypeClasses #-}+{-# LANGUAGE Safe #-} {-# LANGUAGE TypeFamilies #-} {-# LANGUAGE UndecidableInstances #-}
test/Doctest.hs view
@@ -1,14 +1,5 @@-{-# LANGUAGE CPP #-}- module Main (main) where -#if defined(mingw32_HOST_OS) || __GLASGOW_HASKELL__ < 802--main :: IO ()-main = return ()--#else- import System.FilePath.Glob (glob) import Test.DocTest (doctest) @@ -16,5 +7,3 @@ main = do sourceFiles <- glob "src/**/*.hs" doctest $ "-XNoImplicitPrelude" : sourceFiles--#endif
test/Spec.hs view
@@ -1,4 +1,6 @@-module Main where+module Main+ ( main+ ) where import Test.Tasty (defaultMain)
universum.cabal view
@@ -1,5 +1,6 @@+cabal-version: 2.2 name: universum-version: 1.6.1+version: 1.7.0 synopsis: Custom prelude used in Serokell description: See README.md file for more details. homepage: https://github.com/serokell/universum@@ -11,13 +12,11 @@ category: Prelude stability: stable build-type: Simple-cabal-version: >=1.18 bug-reports: https://github.com/serokell/universum/issues-tested-with: GHC == 8.0.2- , GHC == 8.2.2- , GHC == 8.4.3+tested-with: GHC == 8.4.4 , GHC == 8.6.5- , GHC == 8.8.1+ , GHC == 8.8.3+ , GHC == 8.10.1 extra-doc-files: CHANGES.md , CONTRIBUTING.md , README.md@@ -26,7 +25,28 @@ type: git location: git@github.com:serokell/universum.git +common common-options+ build-depends: base >= 4.8 && < 5+ ghc-options:+ -- Source: https://medium.com/mercury-bank/enable-all-the-warnings-a0517bc081c3+ -Weverything+ -Wno-missing-exported-signatures+ -Wno-missing-import-lists+ -Wno-missed-specialisations+ -Wno-all-missed-specialisations+ -Wno-unsafe+ -Wno-safe+ -Wno-missing-local-signatures+ -Wno-monomorphism-restriction+ -Wno-implicit-prelude+ if impl(ghc >= 8.10.1)+ ghc-options: -Wno-prepositive-qualified-module+ -Wno-inferred-safe-imports++ default-language: Haskell2010+ library+ import: common-options hs-source-dirs: src exposed-modules: Universum@@ -70,10 +90,7 @@ Universum.Unsafe Universum.VarArg - ghc-options: -Wall -fwarn-implicit-prelude-- build-depends: base >= 4.8 && < 5- , bytestring+ build-depends: bytestring , containers , deepseq , ghc-prim >= 0.4.0.0@@ -91,53 +108,62 @@ , utf8-string , vector - default-language: Haskell2010+ ghc-options: -Wimplicit-prelude default-extensions: NoImplicitPrelude OverloadedStrings test-suite universum-test+ import: common-options type: exitcode-stdio-1.0 hs-source-dirs: test main-is: Spec.hs other-modules: Test.Universum.Property - build-depends: base >= 4.8 && < 5- , universum+ build-depends: universum , bytestring , text- , utf8-string , hedgehog , tasty , tasty-hedgehog - ghc-options: -Wall -threaded- default-language: Haskell2010+ if impl(ghc >= 8.10.1)+ ghc-options: -Wno-missing-safe-haskell-mode + ghc-options: -threaded+ test-suite universum-doctest+ import: common-options+ if os(windows)+ buildable: False+ type: exitcode-stdio-1.0 hs-source-dirs: test main-is: Doctest.hs - build-depends: base >= 4.8 && < 5- , doctest+ build-depends: doctest , Glob + if impl(ghc >= 8.10.1)+ ghc-options: -Wno-missing-safe-haskell-mode+ ghc-options: -threaded- default-language: Haskell2010 benchmark universum-benchmark+ import: common-options type: exitcode-stdio-1.0- default-language: Haskell2010- ghc-options: -Wall -threaded -rtsopts -with-rtsopts=-N+ ghc-options: -threaded -rtsopts -with-rtsopts=-N+ hs-source-dirs: benchmark main-is: Main.hs- build-depends: base < 5- , universum+ build-depends: universum , containers , gauge , text , unordered-containers++ if impl(ghc >= 8.10.1)+ ghc-options: -Wno-missing-safe-haskell-mode default-extensions: NoImplicitPrelude ScopedTypeVariables