records-sop 0.1.0.3 → 0.1.1.0
raw patch · 4 files changed
+38/−4 lines, 4 filesdep ~ghc-primPVP: major bump suggested
API removals or changes: PVP suggests a major version bump
Dependency ranges changed: ghc-prim
API changes (from Hackage documentation)
- Generics.SOP.Record.SubTyping: instance (a1 Data.Type.Equality.~ a2) => Generics.SOP.Record.SubTyping.IsElemOf' 'GHC.Types.True s a1 s a2 r
+ Generics.SOP.Record.SubTyping: get :: IsElemOf s a r => Record r -> a
+ Generics.SOP.Record.SubTyping: getField :: forall s a b ra. (IsRecord a ra, IsElemOf s b ra) => a -> b
+ Generics.SOP.Record.SubTyping: instance (a1 GHC.Types.~ a2) => Generics.SOP.Record.SubTyping.IsElemOf' 'GHC.Types.True s a1 s a2 r
- Generics.SOP.Record: P :: Snd p -> P
+ Generics.SOP.Record: P :: Snd p -> P (p :: (a, Type))
Files
- CHANGELOG.md +4/−0
- records-sop.cabal +3/−3
- src/Generics/SOP/Record/SubTyping.hs +8/−0
- tests/Examples.hs +23/−1
CHANGELOG.md view
@@ -1,3 +1,7 @@+# 0.1.1.0 (2020-04-09)++* Export `get` and add `getField`.+ # 0.1.0.3 (2019-05-09) * Compatibility with `generics-sop-0.5`.
records-sop.cabal view
@@ -1,12 +1,12 @@ name: records-sop-version: 0.1.0.3+version: 0.1.1.0 author: Andres Löh <andres@well-typed.com> maintainer: andres@well-typed.com license: BSD3 license-file: LICENSE cabal-version: >= 1.10 build-type: Simple-tested-with: GHC == 8.0.2, GHC == 8.2.1, GHC == 8.4.4, GHC == 8.6.5+tested-with: GHC == 8.0.2, GHC == 8.2.2, GHC == 8.4.4, GHC == 8.6.5, GHC == 8.8.2, GHC == 8.10.4, GHC == 9.0.1 category: Generics synopsis: Record subtyping and record utilities with generics-sop description:@@ -34,7 +34,7 @@ base >= 4.9 && < 5.0, deepseq >= 1.3 && < 1.5, generics-sop >= 0.3 && < 0.6,- ghc-prim >= 0.5 && < 0.6+ ghc-prim >= 0.5 && < 0.8 default-language: Haskell2010
src/Generics/SOP/Record/SubTyping.hs view
@@ -16,6 +16,8 @@ ( cast , IsSubTypeOf , IsElemOf+ , get+ , getField ) where @@ -31,6 +33,12 @@ -- cast :: (IsRecord a ra, IsRecord b rb, IsSubTypeOf ra rb) => a -> b cast = fromRecord . castRecord . toRecord++-- | Extract a record field based on the symbolic name of a field.+-- Requires an explicit type application for the field name.+--+getField :: forall s a b ra . (IsRecord a ra, IsElemOf s b ra) => a -> b+getField = get @s . toRecord -- | Class that checks whether one record code is convertible into another. --
tests/Examples.hs view
@@ -1,6 +1,8 @@ {-# LANGUAGE- DeriveGeneric+ DataKinds+ , DeriveGeneric , DuplicateRecordFields+ , TypeApplications #-} {-# OPTIONS_GHC -fdefer-type-errors -Wno-deferred-type-errors #-} module Main where@@ -169,3 +171,23 @@ it "fails to cast G to anything (even X)" $ shouldNotTypecheck (cast g :: X) -}+ it "successfully extracts anInt from A" $+ getField @"anInt" a `shouldBe` 3+ it "successfully extracts aBool from A" $+ getField @"aBool" a `shouldBe` True+ it "correctly fails to extract aChar from A" $+ shouldNotTypecheck (getField @"aChar" a)+ it "successfully extracts anInt from B" $+ getField @"anInt" b `shouldBe` 3+ it "successfully extracts aBool from B" $+ getField @"aBool" b `shouldBe` True+ it "successfully extracts aChar from B" $+ getField @"aChar" b `shouldBe` 'x'+ it "successfully extracts anInt from C" $+ getField @"anInt" c `shouldBe` 3+ it "successfully extracts aBool from C" $+ getField @"aBool" c `shouldBe` True+ it "successfully extracts aChar from C" $+ getField @"aChar" c `shouldBe` 'x'+ it "successfully extracts the first anInt from D" $+ getField @"anInt" d' `shouldBe` 3