sized 1.0.0.2 → 1.1.0.0
raw patch · 7 files changed
+90/−48 lines, 7 filesdep +primitivedep −tasty-expected-failuredep ~ghc-typelits-presburgerdep ~subcategoriesdep ~type-natural
Dependencies added: primitive
Dependencies removed: tasty-expected-failure
Dependency ranges changed: ghc-typelits-presburger, subcategories, type-natural
Files
- Changelog.md +42/−0
- sized.cabal +10/−11
- src/Data/Sized.hs +19/−19
- src/Data/Sized/Flipped.hs +2/−5
- src/Data/Sized/Internal.hs +2/−4
- test/Shared.hs +4/−2
- test/opt-test.hs +11/−7
+ Changelog.md view
@@ -0,0 +1,42 @@+# Changelog++## 1.1.0.0++* Supports GHC 9.6+* Migrates to recent toolchains++## 1.0.0.1++* Minor refactoring of test-suite to support inspection-testiong 0.5++## 1.0.0.0++* Drops Peano-numerals+* Obsolete kind-generic classes+* Now all types are kinded with GHC's builtin type-level naturals, and no type parameters for naturals.+* Drops dependency for `singletons` package and their relatives.++## 0.9.0.0++* This is transitional change: preparation for future rework of `type-natural`+ - Types and constraints in `Data.Sized.Builtin` is now incompatible with `Data.Sized` and `Data.Sized.Peano`+ - The latter two modules will be removed in future release.+* Removes `NilL` and `NilR`+* Compolete overhaul on `Data.Sized.Builtin`+ - Stop using orders from `Data.Singletons`+ - Types of nested pattern synonyms can now be inferred correctly++## 0.8.0.0++* Makes `sLength` using `KnownNat` instance to get O(1) always.+* Introduces `Nil` pattern and deprecates `NilL` and `NilR`.+* Previously, in sepcialised modules for `Builtin` and `Peano`,+ `elemIndex`, `elemIndices` and their Ordinal version were misimplemented;+ they are now correctly uses their counterparts in `Data.Sized`.+* Adds documentation for specialised modules.++## 0.7.0.0++* Stop using `ListLike` package and switched to [`subcategories`] package for the abstraction of sequential types.+* Complete overhaul on type signatures.+* Both `Data.Sized.Builtin` and `Data.Sized.Peano` exports specialised functions instead of reexporting functions from `Data.Sized`.
sized.cabal view
@@ -1,11 +1,12 @@ cabal-version: 2.0 name: sized-version: 1.0.0.2+version: 1.1.0.0 license: BSD3 license-file: LICENSE maintainer: konn.jinro_at_gmail.com author: Hiromi ISHII-tested-with: GHC ==8.8.4 || ==8.10.7 || ==9.0.2 || ==9.2.5 || ==9.4.3+tested-with: GHC ==8.8.4 || ==8.10.7 || ==9.0.2 || ==9.2.7 || ==9.4.4 || ==9.6.1+extra-doc-files: ./Changelog.md synopsis: Sized sequence data-types description: A wrapper to make length-parametrized data-type from functorial data-types.@@ -17,6 +18,7 @@ type: git location: git://github.com/konn/sized.git + library exposed-modules: Data.Sized@@ -26,7 +28,7 @@ hs-source-dirs: src other-modules: Data.Sized.Internal default-language: Haskell2010- ghc-options: -O2 -Wall -Wno-redundant-constraints+ ghc-options: -Wall -Wno-redundant-constraints build-depends: base >=4 && <5 , constraints@@ -34,34 +36,31 @@ , deepseq >=1.4 , equational-reasoning >=0.5 , ghc-typelits-knownnat- , ghc-typelits-presburger >=0.5+ , ghc-typelits-presburger >=0.7.2 , hashable >=1.2 , lens >=0.14 , mono-traversable >=0.10- , subcategories+ , subcategories >=0.2 , these- , type-natural >=1.0+ , type-natural >=1.3 , vector >=0.12 - if impl(ghc >=9.4)- build-depends: ghc-typelits-presburger >=0.7.1- test-suite optimisaion-test type: exitcode-stdio-1.0 main-is: opt-test.hs hs-source-dirs: test other-modules: Shared default-language: Haskell2010- ghc-options: -O2 -Wall -Wno-redundant-constraints -fno-hpc+ ghc-options: -Wall -Wno-redundant-constraints -fno-hpc build-depends: base , containers , inspection-testing >=0.4 && <0.6 , mono-traversable+ , primitive , sized , subcategories , tasty- , tasty-expected-failure , tasty-inspection-testing , template-haskell , th-lift
src/Data/Sized.hs view
@@ -1,6 +1,6 @@ {-# LANGUAGE AllowAmbiguousTypes #-}-{-# LANGUAGE CPP #-} {-# LANGUAGE ConstraintKinds #-}+{-# LANGUAGE DataKinds #-} {-# LANGUAGE DeriveDataTypeable #-} {-# LANGUAGE DerivingStrategies #-} {-# LANGUAGE FlexibleContexts #-}@@ -10,13 +10,13 @@ {-# LANGUAGE LiberalTypeSynonyms #-} {-# LANGUAGE MultiParamTypeClasses #-} {-# LANGUAGE PatternSynonyms #-}+{-# LANGUAGE PolyKinds #-} {-# LANGUAGE QuantifiedConstraints #-} {-# LANGUAGE RankNTypes #-} {-# LANGUAGE ScopedTypeVariables #-} {-# LANGUAGE StandaloneDeriving #-} {-# LANGUAGE TypeApplications #-} {-# LANGUAGE TypeFamilies #-}-{-# LANGUAGE TypeInType #-} {-# LANGUAGE TypeOperators #-} {-# LANGUAGE UndecidableInstances #-} {-# LANGUAGE UndecidableSuperClasses #-}@@ -25,7 +25,7 @@ {-# LANGUAGE NoStarIsType #-} {-# OPTIONS_GHC -fenable-rewrite-rules #-} {-# OPTIONS_GHC -fno-warn-type-defaults -fno-warn-orphans #-}-{-# OPTIONS_GHC -fplugin GHC.TypeLits.Presburger #-}+{-# OPTIONS_GHC -fplugin Data.Type.Natural.Presburger.MinMaxSolver #-} {- | This module provides the functionality to make length-parametrized types from existing 'CFreeMonoid' sequential types.@@ -278,7 +278,7 @@ (Dom f a, KnownNat n) => Sized f n a -> Int-length = const $ fromIntegral $ toNatural $ sNat @n+length = const $ fromIntegral $ fromSNat $ sNat @n {-# INLINE CONLIKE [1] length #-} lengthTLZero :: Sized f 0 a -> Int@@ -539,7 +539,7 @@ SNat n -> Sized f m a -> Sized f n a-take = coerce $ ctake @f @a . P.fromIntegral . toNatural @n+take = coerce $ ctake @f @a . P.fromIntegral . fromSNat @n {-# INLINE take #-} {- | @'takeAtMost' k xs@ takes first at most @k@ elements of @xs@.@@ -552,7 +552,7 @@ SNat n -> Sized f m a -> Sized f (Min n m) a-takeAtMost = coerce $ ctake @f @a . P.fromIntegral . toNatural @n+takeAtMost = coerce $ ctake @f @a . P.fromIntegral . fromSNat @n {-# INLINE takeAtMost #-} {- | @drop k xs@ drops first @k@ element of @xs@ and returns@@ -566,7 +566,7 @@ SNat n -> Sized f m a -> Sized f (m - n) a-drop = coerce $ cdrop @f @a . P.fromIntegral . toNatural @n+drop = coerce $ cdrop @f @a . P.fromIntegral . fromSNat @n {-# INLINE drop #-} {- | @splitAt k xs@ split @xs@ at @k@, where@@ -581,7 +581,7 @@ Sized f m a -> (Sized f n a, Sized f (m -. n) a) splitAt =- coerce $ csplitAt @f @a . P.fromIntegral . toNatural @n+ coerce $ csplitAt @f @a . P.fromIntegral . fromSNat @n {-# INLINE splitAt #-} {- | @splitAtMost k xs@ split @xs@ at @k@.@@ -596,7 +596,7 @@ Sized f m a -> (Sized f (Min n m) a, Sized f (m -. n) a) splitAtMost =- coerce $ csplitAt @f @a . P.fromIntegral . toNatural @n+ coerce $ csplitAt @f @a . P.fromIntegral . fromSNat @n {-# INLINE splitAtMost #-} --------------------------------------------------------------------------------@@ -652,7 +652,7 @@ SNat n -> a -> Sized f n a-replicate = coerce $ creplicate @f @a . P.fromIntegral . toNatural @n+replicate = coerce $ creplicate @f @a . P.fromIntegral . fromSNat @n {-# INLINE replicate #-} {- | 'replicate' with the length inferred.@@ -679,7 +679,7 @@ Sized f n a generate = coerce $ \sn -> withKnownNat sn $- cgenerate @f @a (P.fromIntegral $ toNatural @n sn)+ cgenerate @f @a (P.fromIntegral $ fromSNat @n sn) . (. toEnum @(Ordinal n)) {-# INLINE [1] generate #-} @@ -700,7 +700,7 @@ SNat n -> (Ordinal n -> a) -> Sized V.Vector n a-genVector n f = withKnownNat n $ Sized $ V.generate (P.fromIntegral $ toNatural n) (f . toEnum)+genVector n f = withKnownNat n $ Sized $ V.generate (P.fromIntegral $ fromSNat n) (f . toEnum) {-# INLINE genVector #-} genSVector ::@@ -709,7 +709,7 @@ SNat n -> (Ordinal n -> a) -> Sized SV.Vector n a-genSVector n f = withKnownNat n $ Sized $ SV.generate (P.fromIntegral $ toNatural n) (f . toEnum)+genSVector n f = withKnownNat n $ Sized $ SV.generate (P.fromIntegral $ fromSNat n) (f . toEnum) {-# INLINE genSVector #-} genSeq ::@@ -717,7 +717,7 @@ SNat n -> (Ordinal n -> a) -> Sized Seq.Seq n a-genSeq n f = withKnownNat n $ Sized $ Seq.fromFunction (P.fromIntegral $ toNatural n) (f . toEnum)+genSeq n f = withKnownNat n $ Sized $ Seq.fromFunction (P.fromIntegral $ fromSNat n) (f . toEnum) {-# INLINE genSeq #-} {-# RULES@@ -731,7 +731,7 @@ (n :: SNat (n :: Nat)) (f :: UV.Unbox a => Ordinal n -> a). generate n f =- withKnownNat n $ Sized (UV.generate (P.fromIntegral $ toNatural n) (f . toEnum))+ withKnownNat n $ Sized (UV.generate (P.fromIntegral $ fromSNat n) (f . toEnum)) "generate/Seq" [~1] generate = genSeq #-} @@ -1063,7 +1063,7 @@ Maybe (Sized f n a) fromList Zero _ = Just $ Sized (mempty :: f a) fromList sn xs =- let len = P.fromIntegral $ toNatural sn+ let len = P.fromIntegral $ fromSNat sn in if P.length xs < len then Nothing else Just $ Sized $ ctake len $ cfromList xs@@ -1137,7 +1137,7 @@ [a] -> Sized f n a fromListWithDefault sn def xs =- let len = P.fromIntegral $ toNatural sn+ let len = P.fromIntegral $ fromSNat sn in Sized $ cfromList (ctake len xs) <> creplicate (len - clength xs) def@@ -1181,7 +1181,7 @@ f a -> Maybe (Sized f n a) toSized sn xs =- let len = P.fromIntegral $ toNatural sn+ let len = P.fromIntegral $ fromSNat sn in if clength xs < len then Nothing else Just $ unsafeToSized sn $ ctake len xs@@ -1232,7 +1232,7 @@ f a -> Sized f n a toSizedWithDefault sn def xs =- let len = P.fromIntegral $ toNatural sn+ let len = P.fromIntegral $ fromSNat sn in Sized $ ctake len xs <> creplicate (len - clength xs) def {-# INLINEABLE toSizedWithDefault #-}
src/Data/Sized/Flipped.hs view
@@ -1,5 +1,5 @@-{-# LANGUAGE CPP #-} {-# LANGUAGE ConstraintKinds #-}+{-# LANGUAGE DataKinds #-} {-# LANGUAGE DeriveDataTypeable #-} {-# LANGUAGE DeriveTraversable #-} {-# LANGUAGE EmptyDataDecls #-}@@ -9,19 +9,16 @@ {-# LANGUAGE LiberalTypeSynonyms #-} {-# LANGUAGE MultiParamTypeClasses #-} {-# LANGUAGE PatternSynonyms #-}+{-# LANGUAGE PolyKinds #-} {-# LANGUAGE RankNTypes #-} {-# LANGUAGE ScopedTypeVariables #-} {-# LANGUAGE StandaloneDeriving #-} {-# LANGUAGE TemplateHaskell #-} {-# LANGUAGE TypeFamilies #-}-{-# LANGUAGE TypeInType #-} {-# LANGUAGE TypeOperators #-} {-# LANGUAGE UndecidableInstances #-} {-# LANGUAGE ViewPatterns #-}--#if __GLASGOW_HASKELL__ && __GLASGOW_HASKELL__ >= 806 {-# LANGUAGE NoStarIsType #-}-#endif module Data.Sized.Flipped (Flipped (..)) where import Control.DeepSeq (NFData (..))
src/Data/Sized/Internal.hs view
@@ -1,13 +1,11 @@-{-# LANGUAGE CPP, ConstraintKinds, DataKinds, DeriveDataTypeable #-}+{-# LANGUAGE ConstraintKinds, DataKinds, DeriveDataTypeable #-} {-# LANGUAGE DeriveFunctor, DeriveTraversable, DerivingStrategies #-} {-# LANGUAGE ExplicitNamespaces, FlexibleContexts, FlexibleInstances #-} {-# LANGUAGE GeneralizedNewtypeDeriving, KindSignatures #-} {-# LANGUAGE LiberalTypeSynonyms, MultiParamTypeClasses, PolyKinds #-} {-# LANGUAGE RankNTypes, ScopedTypeVariables, StandaloneDeriving #-}-{-# LANGUAGE TypeFamilies, TypeInType, TypeOperators, UndecidableInstances #-}-#if __GLASGOW_HASKELL__ && __GLASGOW_HASKELL__ >= 806+{-# LANGUAGE TypeFamilies, DataKinds, PolyKinds, TypeOperators, UndecidableInstances #-} {-# LANGUAGE NoStarIsType #-}-#endif {-# OPTIONS_GHC -fno-warn-orphans #-} module Data.Sized.Internal (Sized(..)) where import Control.DeepSeq (NFData (..))
@@ -10,11 +10,13 @@ inspecting :: String -> Obligation -> ExpQ inspecting title obl = inspectTest $ obl {testName = Just title} -data GHCVer = GHC8_8 | GHC8_10 | GHC9_0 | GHC9_2 | GHC9_4+data GHCVer = GHC8_8 | GHC8_10 | GHC9_0 | GHC9_2 | GHC9_4 | GHC9_6 deriving (Show, Eq, Ord) ghcVer :: GHCVer-#if __GLASGOW_HASKELL__ == 904+#if __GLASGOW_HASKELL__ == 906+ghcVer = GHC9_6+#elif __GLASGOW_HASKELL__ == 904 ghcVer = GHC9_4 #elif __GLASGOW_HASKELL__ == 902 ghcVer = GHC9_2
test/opt-test.hs view
@@ -10,7 +10,6 @@ module Main where import Control.Subcategory-import Data.Function ((&)) import qualified Data.Sequence as Seq import Data.Sized (Sized, zipWithSame) import qualified Data.Sized as SV@@ -24,8 +23,9 @@ import Numeric.Natural (Natural) import Shared import Test.Tasty-import Test.Tasty.ExpectedFailure (expectFailBecause) import Test.Tasty.Inspection+import qualified Data.Vector.Generic.Mutable as MV+import Control.Monad.Primitive (PrimMonad) type LSized = Sized [] @@ -149,13 +149,17 @@ ] , testGroup "Unboxed Vector"- [ $( inspecting "doesn't contain type classes except for Unbox" $+ [ $( inspecting "doesn't contain type classes except for Unbox, and Vector, MVector (>= GHC 9)" $ 'zipWithSame_Unboxed- `hasNoTypeClassesExcept` [''Unbox]+ `hasNoTypeClassesExcept`+ if ghcVer >= GHC9_0 + then + if ghcVer >= GHC9_6+ then [''Unbox, ''G.Vector, ''MV.MVector]+ else [''Unbox, ''G.Vector, ''MV.MVector, ''Monad, ''PrimMonad]+ else [''Unbox] )- & if ghcVer >= GHC9_0- then expectFailBecause "This suffers from Simplified Subsumption"- else id+ , $( inspecting "doesn't contain type classes if fully instnatiated" $ hasNoTypeClasses 'zipWithSame_Unboxed_monomorphic )