universe-base 1.1.1 → 1.1.2
raw patch · 5 files changed
+122/−35 lines, 5 filesdep ~QuickCheckdep ~basedep ~semigroups
Dependency ranges changed: QuickCheck, base, semigroups, tagged, void
Files
- changelog +4/−0
- src/Data/Universe/Class.hs +54/−3
- src/Data/Universe/Generic.hs +19/−6
- src/Data/Universe/Helpers.hs +6/−0
- universe-base.cabal +39/−26
changelog view
@@ -1,3 +1,7 @@+1.1.2++* Explicitly mark modules as Safe or Trustworthy+ 1.1.1 * Make Data.Universe.Helpers.cartesianProduct more generative
src/Data/Universe/Class.hs view
@@ -3,6 +3,12 @@ #ifdef DEFAULT_SIGNATURES {-# LANGUAGE DefaultSignatures #-} #endif+{-# LANGUAGE CPP #-}+#if __GLASGOW_HASKELL__ >=704+{-# LANGUAGE Safe #-}+#elif __GLASGOW_HASKELL__ >=702+{-# LANGUAGE Trustworthy #-}+#endif -- | Bottoms are ignored for this entire module: -- only fully-defined inhabitants are considered inhabitants. module Data.Universe.Class@@ -39,6 +45,10 @@ -- $setup -- >>> import Data.List+-- >>> import Data.Universe.Helpers+--+-- -- Show (a -> b) instance (in universe-reverse-instances, but cannot depend on it here).+-- >>> instance (Finite a, Show a, Show b) => Show (a -> b) where showsPrec n f = showsPrec n [(a, f a) | a <- universeF] -- | Creating an instance of this class is a declaration that your type is -- recursively enumerable (and that 'universe' is that enumeration). In@@ -221,9 +231,16 @@ -- ------------------------------------------------------------------------------- --- could change the Ord constraint to an Eq one, but come on, how many finite--- types can't be ordered?+-- |+-- >>> mapM_ print (universe :: [Bool -> Bool])+-- [(False,False),(True,False)]+-- [(False,False),(True,True)]+-- [(False,True),(True,False)]+-- [(False,True),(True,True)]+-- instance (Finite a, Ord a, Universe b) => Universe (a -> b) where+ -- could change the Ord constraint to an Eq one, but come on, how many finite+ -- types can't be ordered? universe = map tableToFunction tables where tables = choices [universe | _ <- monoUniverse] tableToFunction = (!) . fromList . zip monoUniverse@@ -295,6 +312,19 @@ instance Finite a => Finite (Semi.First a) where universeF = map Semi.First universeF; cardinality = retagWith Semi.First cardinality instance Finite a => Finite (Semi.Last a) where universeF = map Semi.Last universeF; cardinality = retagWith Semi.Last cardinality +-- |+-- >>> mapM_ print (universeF :: [Bool -> Bool])+-- [(False,False),(True,False)]+-- [(False,False),(True,True)]+-- [(False,True),(True,False)]+-- [(False,True),(True,True)]+--+-- >>> cardinality :: Tagged (Bool -> Ordering) Natural+-- Tagged 9+--+-- >>> cardinality :: Tagged (Ordering -> Bool) Natural+-- Tagged 8+-- instance (Ord a, Finite a, Finite b) => Finite (a -> b) where universeF = map tableToFunction tables where tables = sequence [universeF | _ <- monoUniverse]@@ -327,6 +357,14 @@ -- containers ------------------------------------------------------------------------------- +-- |+-- >>> import qualified Data.Set as Set+-- >>> mapM_ print (universe :: [Set.Set Bool])+-- fromList []+-- fromList [False]+-- fromList [True]+-- fromList [False,True]+-- instance (Ord a, Universe a) => Universe (Set.Set a) where universe = Set.empty : go universe where@@ -337,10 +375,23 @@ inter [] = [] inter (y:ys) = y : Set.insert x y : inter ys - instance (Ord a, Finite a) => Finite (Set.Set a) where cardinality = retag (fmap (2 ^) (cardinality :: Tagged a Natural)) +-- |+-- >>> import qualified Data.Map as Map+-- >>> mapM_ print (universe :: [Map.Map Bool Bool])+-- fromList []+-- fromList [(True,False)]+-- fromList [(False,False)]+-- fromList [(True,True)]+-- fromList [(False,False),(True,False)]+-- fromList [(False,True)]+-- fromList [(False,False),(True,True)]+-- fromList [(False,True),(True,False)]+-- fromList [(False,True),(True,True)]+--+-- instance (Ord k, Finite k, Universe v) => Universe (Map.Map k v) where universe = map tableToFunction tables where tables = choices [universe | _ <- monoUniverse]
src/Data/Universe/Generic.hs view
@@ -1,5 +1,11 @@+{-# LANGUAGE CPP #-} {-# LANGUAGE TypeOperators #-} {-# LANGUAGE FlexibleContexts #-}+#if __GLASGOW_HASKELL__ >=704+{-# LANGUAGE Safe #-}+#elif __GLASGOW_HASKELL__ >=702+{-# LANGUAGE Trustworthy #-}+#endif module Data.Universe.Generic where import GHC.Generics@@ -8,13 +14,14 @@ import Data.Universe.Helpers -- $setup--- >>> :set -XDeriveGeneric -XEmptyDataDeriving+-- >>> :set -XDeriveGeneric+-- >>> import GHC.Generics class GUniverse f where guniverse :: [f a] instance GUniverseSum f => GUniverse (M1 i c f) where- guniverse = map M1 $ interleave $ guniverseSum+ guniverse = map M1 $ interleave guniverseSum class GUniverseSum f where guniverseSum :: [[f a]]@@ -46,10 +53,6 @@ -- | ----- >>> data Zero deriving (Show, Generic)--- >>> universeGeneric :: [Zero]--- []--- -- >>> data One = One deriving (Show, Generic) -- >>> universeGeneric :: [One] -- [One]@@ -69,3 +72,13 @@ -- universeGeneric :: (Generic a, GUniverse (Rep a)) => [a] universeGeneric = map to guniverse ++#if __GLASGOW_HASKELL__ >= 804+-- $empty+--+-- >>> :set -XEmptyDataDeriving+--+-- >>> data Zero deriving (Show, Generic)+-- >>> universeGeneric :: [Zero]+-- []+#endif
src/Data/Universe/Helpers.hs view
@@ -1,3 +1,9 @@+{-# LANGUAGE CPP #-}+#if __GLASGOW_HASKELL__ >=704+{-# LANGUAGE Safe #-}+#elif __GLASGOW_HASKELL__ >=702+{-# LANGUAGE Trustworthy #-}+#endif module Data.Universe.Helpers ( -- | This module is for functions that are useful for writing instances, -- but not necessarily for using them (and hence are not exported by the
universe-base.cabal view
@@ -1,6 +1,6 @@-name: universe-base-version: 1.1.1-synopsis: A class for finite and recursively enumerable types.+name: universe-base+version: 1.1.2+synopsis: A class for finite and recursively enumerable types. description: A class for finite and recursively enumerable types and some helper functions for enumerating them. .@@ -13,18 +13,28 @@ for types in GHC boot libraries. For more instances check @universe-instances-*@ packages. -homepage: https://github.com/dmwit/universe-license: BSD3-license-file: LICENSE-author: Daniel Wagner-maintainer: me@dmwit.com-copyright: 2014 Daniel Wagner-category: Data-build-type: Simple-cabal-version: >=1.10+homepage: https://github.com/dmwit/universe+license: BSD3+license-file: LICENSE+author: Daniel Wagner+maintainer: me@dmwit.com+copyright: 2014 Daniel Wagner+category: Data+build-type: Simple+cabal-version: >=1.10 extra-source-files: changelog tested-with:- GHC ==8.8.1 || ==8.6.4 || ==8.4.4 || ==8.2.2 || ==8.0.2 || ==7.10.3 || ==7.8.4 || ==7.6.3 || ==7.4.2 || ==7.0.4+ GHC ==7.0.4+ || ==7.4.2+ || ==7.6.3+ || ==7.8.4+ || ==7.10.3+ || ==8.0.2+ || ==8.2.2+ || ==8.4.4+ || ==8.6.5+ || ==8.8.4+ || ==8.10.3 source-repository head type: git@@ -33,7 +43,7 @@ source-repository this type: git location: https://github.com/dmwit/universe- tag: base-1.1+ tag: instances-extended-1.1 library default-language: Haskell2010@@ -42,12 +52,11 @@ Data.Universe.Class Data.Universe.Helpers - if impl(ghc >= 7.2)- exposed-modules:- Data.Universe.Generic+ if impl(ghc >=7.2)+ exposed-modules: Data.Universe.Generic+ if impl(ghc <7.6)- build-depends:- ghc-prim+ build-depends: ghc-prim other-extensions: BangPatterns@@ -57,9 +66,9 @@ TypeFamilies build-depends:- base >=4.3 && <4.13+ base >=4.3 && <4.16 , containers >=0.4.0.0 && <0.7- , tagged >=0.8.4 && <0.9+ , tagged >=0.8.6.1 && <0.9 , transformers >=0.3.0.0 && <0.6 if impl(ghc >=7.10.3)@@ -71,15 +80,20 @@ if !impl(ghc >=7.10) build-depends: nats >=1.1.2 && <1.2- , void >=0.7.2 && <0.8+ , void >=0.7.3 && <0.8 if !impl(ghc >=8.0)- build-depends: semigroups >=0.18.2 && <0.20+ build-depends: semigroups >=0.18.5 && <0.20 if impl(ghc >=7.4) cpp-options: -DDEFAULT_SIGNATURES other-extensions: DefaultSignatures + if impl(ghc >= 9.0)+ -- these flags may abort compilation with GHC-8.10+ -- https://gitlab.haskell.org/ghc/ghc/-/merge_requests/3295+ ghc-options: -Winferred-safe-imports -Wmissing-safe-haskell-mode+ test-suite tests default-language: Haskell2010 other-extensions: ScopedTypeVariables@@ -90,9 +104,8 @@ build-depends: base , containers- , QuickCheck >=2.8.2 && <2.14+ , QuickCheck >=2.8.2 && <2.15 , universe-base if !impl(ghc >=7.10)- build-depends:- nats+ build-depends: nats