generic-optics 2.2.1.0 → 2.3.0.0
raw patch · 11 files changed
+129/−54 lines, 11 filesdep +mtldep −textdep ~basedep ~generic-lens-coredep ~optics-corenew-uploaderPVP ok
version bump matches the API change (PVP)
Dependencies added: mtl
Dependencies removed: text
Dependency ranges changed: base, generic-lens-core, optics-core
API changes (from Hackage documentation)
+ Data.Generics.Sum.Typed: instance Data.Generics.Sum.Typed.AsType a a
- Data.Generics.Product.Any: class HasAny sel s t a b | s sel -> a
+ Data.Generics.Product.Any: class HasAny (sel :: k) s t a b | s sel -> a
- Data.Generics.Product.Fields: getField :: forall f a s. HasField' f s a => s -> a
+ Data.Generics.Product.Fields: getField :: forall (f :: Symbol) a s. HasField' f s a => s -> a
- Data.Generics.Product.Fields: setField :: forall f s a. HasField' f s a => a -> s -> s
+ Data.Generics.Product.Fields: setField :: forall (f :: Symbol) s a. HasField' f s a => a -> s -> s
- Data.Generics.Product.HList: class IsList (f :: Type) (g :: Type) (as :: [Type]) (bs :: [Type]) | f -> as, g -> bs
+ Data.Generics.Product.HList: class IsList f g (as :: [Type]) (bs :: [Type]) | f -> as, g -> bs
- Data.Generics.Product.Positions: getPosition :: forall i s a. HasPosition' i s a => s -> a
+ Data.Generics.Product.Positions: getPosition :: forall (i :: Nat) s a. HasPosition' i s a => s -> a
- Data.Generics.Product.Positions: setPosition :: forall i s a. HasPosition' i s a => a -> s -> s
+ Data.Generics.Product.Positions: setPosition :: forall (i :: Nat) s a. HasPosition' i s a => a -> s -> s
- Data.Generics.Sum.Any: class AsAny sel a s | s sel -> a
+ Data.Generics.Sum.Any: class AsAny (sel :: k) a s | s sel -> a
- Data.Generics.Wrapped: wrappedFrom :: forall s a. Wrapped s s a a => a -> s
+ Data.Generics.Wrapped: wrappedFrom :: Wrapped s s a a => a -> s
- Data.Generics.Wrapped: wrappedTo :: forall s a. Wrapped s s a a => s -> a
+ Data.Generics.Wrapped: wrappedTo :: Wrapped s s a a => s -> a
Files
- ChangeLog.md +8/−0
- generic-optics.cabal +27/−12
- src/Data/Generics/Product/Fields.hs +2/−1
- src/Data/Generics/Product/Positions.hs +2/−1
- src/Data/Generics/Product/Subtype.hs +4/−2
- src/Data/Generics/Product/Typed.hs +6/−3
- src/Data/Generics/Sum/Constructors.hs +2/−1
- src/Data/Generics/Sum/Subtype.hs +6/−6
- src/Data/Generics/Sum/Typed.hs +31/−4
- test/Spec.hs +24/−24
- test/Test146.hs +17/−0
ChangeLog.md view
@@ -1,3 +1,11 @@+## generic-optics-2.3.0.0 (2025-08-27)++Tested with GHC 8.4 - 9.14 alpha1.++### Breaking API changes:+- `AsType` now includes a reflexive case for consistency with `HasType`: every+ type can be treated 'as' itself.+ ## generic-optics-2.2.1.0 (2022-01-22) - GHC 9.2 compatibility
generic-optics.cabal view
@@ -1,5 +1,6 @@+cabal-version: 2.0 name: generic-optics-version: 2.2.1.0+version: 2.3.0.0 synopsis: Generically derive traversals, lenses and prisms. description: This library uses GHC.Generics to derive efficient optics (traversals, lenses and prisms) for algebraic data types in a type-directed way, with a focus on good type inference and error messages when possible. .@@ -13,13 +14,26 @@ maintainer: kiss.csongor.kiss@gmail.com category: Generics, Records, Lens build-type: Simple-cabal-version: >= 1.10-Tested-With: GHC == 8.4.1, GHC == 8.4.4, GHC == 8.6.5, GHC == 8.8.4, GHC == 8.10.3, GHC == 9.0.1, GHC == 9.2.1 +tested-with:+ GHC == 9.14.1+ GHC == 9.12.2+ GHC == 9.10.2+ GHC == 9.8.4+ GHC == 9.6.7+ GHC == 9.4.8+ GHC == 9.2.8+ GHC == 9.0.2+ GHC == 8.10.7+ GHC == 8.8.4+ GHC == 8.6.5+ GHC == 8.4.4+ extra-source-files: examples/StarWars.hs , examples/Examples.hs- , ChangeLog.md +extra-doc-files: ChangeLog.md+ library exposed-modules: Data.Generics.Wrapped , Data.Generics.Product@@ -42,22 +56,23 @@ other-modules: Data.Generics.Internal.Optics build-depends: base >= 4.11 && < 5- , generic-lens-core == 2.2.1.0- , optics-core >= 0.2 && < 1.0- , text >= 1.2 && < 1.3+ , generic-lens-core ^>= 2.3.0.0+ , optics-core >= 0.2 && < 1 hs-source-dirs: src default-language: Haskell2010+ default-extensions: TypeOperators ghc-options: -Wall test-suite generic-optics-inspection-tests type: exitcode-stdio-1.0 hs-source-dirs: test main-is: Spec.hs- other-modules: Util Test24 Test88 Test25 Test40 Test62 Test63 CustomChildren+ other-modules: Util Test24 Test88 Test25 Test40 Test62 Test63 Test146 CustomChildren - build-depends: base >= 4.11 && <= 5.0+ build-depends: base , generic-optics+ , mtl , optics-core , inspection-testing >= 0.2 , HUnit@@ -70,7 +85,7 @@ hs-source-dirs: test main-is: Bifunctor.hs - build-depends: base >= 4.11 && <= 5.0+ build-depends: base , generic-optics , optics-core , HUnit@@ -83,7 +98,7 @@ hs-source-dirs: test/syb main-is: Tree.hs - build-depends: base >= 4.11 && <= 5.0+ build-depends: base , generic-optics , optics-core , HUnit@@ -96,5 +111,5 @@ type: exitcode-stdio-1.0 ghc-options: -threaded main-is: doctest.hs- build-depends: base >4 && <5, doctest+ build-depends: base >=4 && <5, doctest hs-source-dirs: examples
src/Data/Generics/Product/Fields.hs view
@@ -155,7 +155,8 @@ -- instance {-# OVERLAPPING #-} HasField' field s a => HasField field s s a a where -- field f s = field' @field f s --- | See Note [Uncluttering type signatures]+-- | Uncluttering type signatures (see 'Void')+-- -- >>> :t field -- field :: HasField field s t a b => Lens s t a b instance {-# OVERLAPPING #-} HasField f (Void1 a) (Void1 b) a b where
src/Data/Generics/Product/Positions.hs view
@@ -126,7 +126,8 @@ position = position0 @i {-# INLINE position #-} --- | See Note [Uncluttering type signatures]+-- | Uncluttering type signatures (see 'Void')+-- -- >>> :t position -- position :: HasPosition i s t a b => Lens s t a b instance {-# OVERLAPPING #-} HasPosition f (Void1 a) (Void1 b) a b where
src/Data/Generics/Product/Subtype.hs view
@@ -118,13 +118,15 @@ instance {-# OVERLAPPING #-} Subtype a a where super = Optic id --- | See Note [Uncluttering type signatures]+-- | Uncluttering type signatures (see 'Void')+-- -- >>> :t super -- super :: Subtype sup sub => Lens sub sub sup sup instance {-# OVERLAPPING #-} Subtype a Void where super = undefined --- | See Note [Uncluttering type signatures]+-- | Uncluttering type signatures (see 'Void')+-- -- >>> :t super @Int -- super @Int :: Subtype Int sub => Lens sub sub Int Int instance {-# OVERLAPPING #-} Subtype Void a where
src/Data/Generics/Product/Typed.hs view
@@ -59,7 +59,8 @@ -- human = Human "Tunyasz" 50 "London" False -- :} --- |Records that have a field with a unique type.+-- |Types that contain another type, either by being a record with a field+-- with that type, or by actually being that type. class HasType a s where -- |A lens that focuses on a field with a unique type in its parent type. --@@ -103,6 +104,7 @@ typed = normaliseLens (Optic Core.derived) {-# INLINE typed #-} +-- |Every type 'has' itself. instance {-# OVERLAPPING #-} HasType a a where getTyped = id {-# INLINE getTyped #-}@@ -110,10 +112,11 @@ setTyped a _ = a {-# INLINE setTyped #-} --- | See Note [Uncluttering type signatures]+-- | Uncluttering type signatures (see 'Void')+-- -- >>> :t typed -- typed :: HasType a s => Lens s s a a ----- Note that this might not longer be needed given the above 'HasType a a' instance.+-- Note that this might not longer be needed given the 'HasType a a' instance. instance {-# OVERLAPPING #-} HasType a Void where typed = undefined
src/Data/Generics/Sum/Constructors.hs view
@@ -128,7 +128,8 @@ _Ctor = _Ctor0 @ctor {-# INLINE _Ctor #-} --- | See Note [Uncluttering type signatures]+-- | Uncluttering type signatures (see 'Void')+-- -- >>> :t _Ctor -- _Ctor :: AsConstructor ctor s t a b => Prism s t a b instance {-# OVERLAPPING #-} AsConstructor ctor (Void1 a) (Void1 b) a b where
src/Data/Generics/Sum/Subtype.hs view
@@ -115,16 +115,16 @@ _Sub = Optic id {-# INLINE _Sub #-} --- | See Note [Uncluttering type signatures]---_Sub--- :: (AsSubtype sub sup, Data.Profunctor.Choice.Choice p,--- Applicative f) =>--- p sub (f sub) -> p sup (f sup)+-- | Uncluttering type signatures (see 'Void')+--+-- >>> :t _Sub+--_Sub :: AsSubtype sub sup => Prism' sup sub instance {-# OVERLAPPING #-} AsSubtype a Void where injectSub = undefined projectSub = undefined --- | See Note [Uncluttering type signatures]+-- | Uncluttering type signatures (see 'Void')+-- -- >>> :t _Sub @Int -- _Sub @Int :: AsSubtype Int sup => Prism' sup Int instance {-# OVERLAPPING #-} AsSubtype Void a where
src/Data/Generics/Sum/Typed.hs view
@@ -27,7 +27,7 @@ module Data.Generics.Sum.Typed ( -- *Prisms --- -- $setup+ -- $setup AsType (..) ) where @@ -64,7 +64,8 @@ -- :} --- |Sums that have a constructor with a field of the given type.+-- |Types that can represent another type, either by being a sum with a+-- constructor containing that type, or by actually being that type. class AsType a s where -- |A prism that projects a constructor uniquely identifiable by the type of -- its field.@@ -85,23 +86,48 @@ _Typed = prism injectTyped (\i -> maybe (Left i) Right (projectTyped i)) {-# INLINE _Typed #-} + -- |Inject by type.+ --+ --+ -- >>> :{+ -- dog :: Dog+ -- dog = MkDog "Fido" (Age 11)+ -- dogAsAnimal :: Animal+ -- dogAsAnimal = injectTyped dog+ -- dogAsItself :: Dog+ -- dogAsItself = injectTyped dog+ -- >>> :} injectTyped :: a -> s injectTyped = review _Typed -- |Project by type.+ --+ --+ -- >>> :{+ -- dogAsAnimal :: Animal+ -- dogAsAnimal = Dog (MkDog "Fido" (Age 11))+ -- mDog :: Maybe Dog+ -- mDog = projectTyped dogAsAnimal+ -- >>> :} projectTyped :: s -> Maybe a projectTyped = either (const Nothing) Just . matching _Typed {-# MINIMAL (injectTyped, projectTyped) | _Typed #-} +-- |Every type can be treated 'as' itself.+instance {-# OVERLAPPING #-} AsType a a where+ injectTyped = id+ projectTyped = Just+ instance Core.Context a s => AsType a s where _Typed = normalisePrism (Optic Core.derived) {-# INLINE _Typed #-} --- | See Note [Uncluttering type signatures]+-- | Uncluttering type signatures (see 'Void')+-- -- >>> :t _Typed -- _Typed :: AsType a s => Prism' s a instance {-# OVERLAPPING #-} AsType a Void where@@ -109,7 +135,8 @@ injectTyped = undefined projectTyped = undefined --- | See Note [Uncluttering type signatures]+-- | Uncluttering type signatures (see 'Void')+-- -- >>> :t _Typed @Int -- _Typed @Int :: AsType Int s => Prism' s Int instance {-# OVERLAPPING #-} AsType Void a where
test/Spec.hs view
@@ -29,6 +29,7 @@ -- This is sufficient at we only want to test that they typecheck import Test24 () import Test25 ()+import Test146 () -- import CustomChildren (customTypesTest) @@ -241,27 +242,26 @@ deriving (Show, Eq, Generic) tests :: Test-tests = TestList $ map mkHUnitTest- [- -- $(inspectTest $ 'fieldALensManual === 'fieldALensName)- -- , $(inspectTest $ 'fieldALensManual === 'fieldALensName_)- -- , $(inspectTest $ 'fieldALensManual === 'fieldALensType)- -- , $(inspectTest $ 'fieldALensManual === 'fieldALensPos)- -- , $(inspectTest $ 'fieldALensManual === 'fieldALensPos_)- -- , $(inspectTest $ 'subtypeLensManual === 'subtypeLensGeneric)- -- , $(inspectTest $ 'typeChangingManualInst === 'typeChangingGeneric)- -- , $(inspectTest $ 'typeChangingManualInst === 'typeChangingGenericPos)- $(inspectTest $ 'typeChangingManualCompose === 'typeChangingGenericCompose)- , $(inspectTest $ 'typeChangingManualCompose === 'typeChangingGenericCompose_)- -- , $(inspectTest $ 'sum1PrismManual === 'sum1PrismB) -- TODO fails >=9.0- -- , $(inspectTest $ 'subtypePrismManual === 'subtypePrismGeneric)- -- , $(inspectTest $ 'sum2PrismManualChar === 'sum2TypePrismChar) -- TODO fails >=9.0- -- , $(inspectTest $ 'sum2PrismManual === 'sum2TypePrism) -- TODO fails >=9.0- -- , $(inspectTest $ 'sum1PrismManualChar === 'sum1TypePrismChar) -- TODO fails >=9.0- -- , $(inspectTest $ 'sum2PrismManualChar === 'sum2TypePrismChar) -- TODO fails >=9.0- -- , $(inspectTest $ 'sum1PrismManual === 'sum1TypePrism) -- TODO fails >=9.0- , $(inspectTest $ 'intTraversalManual === 'intTraversalDerived)- -- , $(inspectTest $ 'sum3Param0Manual === 'sum3Param0Derived) -- TODO fails >=9.0- -- , $(inspectTest $ 'sum3Param1Manual === 'sum3Param1Derived) -- TODO fails >=9.0- -- , $(inspectTest $ 'sum3Param2Manual === 'sum3Param2Derived) -- TODO fails >=9.0- ]+tests = TestList $ map mkHUnitTest $+ -- $(inspectTest $ 'fieldALensManual === 'fieldALensName) :+ -- $(inspectTest $ 'fieldALensManual === 'fieldALensName_) :+ -- $(inspectTest $ 'fieldALensManual === 'fieldALensType) :+ -- $(inspectTest $ 'fieldALensManual === 'fieldALensPos) :+ -- $(inspectTest $ 'fieldALensManual === 'fieldALensPos_) :+ -- $(inspectTest $ 'subtypeLensManual === 'subtypeLensGeneric) :+ -- $(inspectTest $ 'typeChangingManualInst === 'typeChangingGeneric) :+ -- $(inspectTest $ 'typeChangingManualInst === 'typeChangingGenericPos) :+ -- $(inspectTest $ 'typeChangingManualCompose === 'typeChangingGenericCompose) : -- TODO fails >=9.12+ -- $(inspectTest $ 'typeChangingManualCompose === 'typeChangingGenericCompose_) : -- TODO fails >=9.12+ -- $(inspectTest $ 'sum1PrismManual === 'sum1PrismB) : -- TODO fails >=9.0+ -- $(inspectTest $ 'subtypePrismManual === 'subtypePrismGeneric) :+ -- $(inspectTest $ 'sum2PrismManualChar === 'sum2TypePrismChar) : -- TODO fails >=9.0+ -- $(inspectTest $ 'sum2PrismManual === 'sum2TypePrism) : -- TODO fails >=9.0+ -- $(inspectTest $ 'sum1PrismManualChar === 'sum1TypePrismChar) : -- TODO fails >=9.0+ -- $(inspectTest $ 'sum2PrismManualChar === 'sum2TypePrismChar) : -- TODO fails >=9.0+ -- $(inspectTest $ 'sum1PrismManual === 'sum1TypePrism) : -- TODO fails >=9.0+ $(inspectTest $ 'intTraversalManual === 'intTraversalDerived) :+ -- $(inspectTest $ 'sum3Param0Manual === 'sum3Param0Derived) : -- TODO fails >=9.0+ -- $(inspectTest $ 'sum3Param1Manual === 'sum3Param1Derived) : -- TODO fails >=9.0+ -- $(inspectTest $ 'sum3Param2Manual === 'sum3Param2Derived) : -- TODO fails >=9.0+ []
+ test/Test146.hs view
@@ -0,0 +1,17 @@+{-# LANGUAGE DeriveGeneric #-}+{-# LANGUAGE FlexibleContexts #-}++module Test146 where++import Control.Monad.Except+import Data.Generics.Sum+import GHC.Generics++data Error = Error+ deriving (Generic)++poly :: (AsType Error e, MonadError e m) => m ()+poly = undefined++mono :: ExceptT Error IO ()+mono = poly