packages feed

records-sop 0.1.1.0 → 0.1.1.1

raw patch · 4 files changed

+61/−39 lines, 4 filesdep ~ghc-primdep ~hspecPVP: major bump suggested

API removals or changes: PVP suggests a major version bump

Dependency ranges changed: ghc-prim, hspec

API changes (from Hackage documentation)

- Generics.SOP.Record: fromRecord :: IsRecord a r => RecordRep a -> a
+ Generics.SOP.Record: fromRecord :: forall a r. IsRecord a r => RecordRep a -> a

Files

records-sop.cabal view
@@ -1,12 +1,12 @@ name: records-sop-version: 0.1.1.0+version: 0.1.1.1 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.2, GHC == 8.4.4, GHC == 8.6.5, GHC == 8.8.2, GHC == 8.10.4, GHC == 9.0.1+tested-with: GHC == 8.0.2, GHC == 8.2.2, GHC == 8.4.4, GHC == 8.6.5, GHC == 8.8.4, GHC == 8.10.7, GHC == 9.0.2, GHC == 9.2.8, GHC == 9.4.5, GHC == 9.6.2 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.8+    ghc-prim >= 0.5 && < 0.11   default-language:     Haskell2010 @@ -50,7 +50,7 @@   build-depends:     base >= 4.9 && < 5.0,     deepseq >= 1.4 && < 1.5,-    hspec >= 2.2 && < 2.8,+    hspec >= 2.2 && < 2.11,     generics-sop >= 0.3 && < 0.6,     records-sop,     should-not-typecheck >= 2.1 && < 2.2
src/Generics/SOP/Record.hs view
@@ -1,16 +1,21 @@-{-# LANGUAGE ConstraintKinds #-} {-# LANGUAGE CPP #-}+{-# LANGUAGE ConstraintKinds #-} {-# LANGUAGE DeriveGeneric #-} {-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE FlexibleInstances #-} {-# LANGUAGE ScopedTypeVariables #-} {-# LANGUAGE StandaloneDeriving #-}-{-# LANGUAGE TypeInType #-} {-# LANGUAGE TypeFamilies #-} {-# LANGUAGE TypeOperators #-} {-# LANGUAGE UndecidableInstances #-}-{-# OPTIONS_GHC -fno-warn-unticked-promoted-constructors #-}-{-# OPTIONS_GHC -fno-warn-redundant-constraints #-}+#if MIN_VERSION_base(4,12,0)+{-# LANGUAGE DataKinds #-}+{-# LANGUAGE PolyKinds #-}+#else+{-# LANGUAGE TypeInType #-}+#endif+{-# OPTIONS_GHC -Wno-unticked-promoted-constructors #-}+{-# OPTIONS_GHC -Wno-redundant-constraints #-} module Generics.SOP.Record   ( -- * A suitable representation for single-constructor records     FieldLabel@@ -221,8 +226,11 @@ unsafeToRecord_NP = unsafeCoerce  -- | Convert a record representation back into a value.-fromRecord :: (IsRecord a r) => RecordRep a -> a-fromRecord = to . SOP . Z . unsafeFromRecord_NP+fromRecord :: forall a r . (IsRecord a r) => RecordRep a -> a+fromRecord = fromRecord'+  where+    fromRecord' :: forall xs . (IsRecord' a r xs) => RecordRep a -> a -- extra type signature should not be necessary, see GHC #21515+    fromRecord' = to . SOP . Z . unsafeFromRecord_NP  -- | Convert a record representation into an n-ary product. This is a no-op, -- and more efficiently implemented using 'unsafeFromRecord_NP'.
src/Generics/SOP/Record/SubTyping.hs view
@@ -1,17 +1,20 @@-{-# LANGUAGE-    AllowAmbiguousTypes-  , FlexibleInstances-  , MultiParamTypeClasses-  , ScopedTypeVariables-  , TypeApplications-  , TypeInType-  , TypeFamilies-  , TypeOperators-  , UndecidableInstances-#-}-{-# OPTIONS_GHC-  -fno-warn-unticked-promoted-constructors-#-}+{-# LANGUAGE AllowAmbiguousTypes #-}+{-# LANGUAGE CPP #-}+{-# LANGUAGE FlexibleContexts #-}+{-# LANGUAGE FlexibleInstances #-}+{-# LANGUAGE MultiParamTypeClasses #-}+{-# LANGUAGE ScopedTypeVariables #-}+{-# LANGUAGE TypeApplications #-}+{-# LANGUAGE TypeFamilies #-}+{-# LANGUAGE TypeOperators #-}+{-# LANGUAGE UndecidableInstances #-}+#if MIN_VERSION_base(4,12,0)+{-# LANGUAGE DataKinds #-}+{-# LANGUAGE PolyKinds #-}+#else+{-# LANGUAGE TypeInType #-}+#endif+{-# OPTIONS_GHC -Wno-unticked-promoted-constructors #-} module Generics.SOP.Record.SubTyping   ( cast   , IsSubTypeOf
tests/Examples.hs view
@@ -1,5 +1,6 @@ {-# LANGUAGE-    DataKinds+    CPP+  , DataKinds   , DeriveGeneric   , DuplicateRecordFields   , TypeApplications@@ -44,13 +45,15 @@ instance HasDatatypeInfo C instance NFData C --- Duplicate label within a single record (works!).+#if __GLASGOW_HASKELL__ < 902+-- Duplicate label within a single record (works prior to ghc-9.2). data D = MkD { anInt :: Int, anInt :: Int }   deriving (Eq, Show, GHC.Generic)  instance Generic D instance HasDatatypeInfo D instance NFData D+#endif  -- Wrong type. data E = MkE { anInt :: Int, aBool :: Bool, aChar :: () }@@ -86,11 +89,13 @@ c :: C c = MkC True 'x' 3 +#if __GLASGOW_HASKELL__ < 902 d :: D d = MkD 3 3  d' :: D d' = MkD 3 4+#endif  e :: E e = MkE 3 True ()@@ -113,8 +118,6 @@       (cast a :: A) `shouldBe` a     it "successfully casts A to X" $       (cast a :: X) `shouldBe` x-    it "successfully casts A to D" $-      (cast a :: D) `shouldBe` d     it "successfully casts B to B" $       (cast b :: B) `shouldBe` b     it "successfully casts B to X" $@@ -123,40 +126,46 @@       (cast b :: A) `shouldBe` a     it "successfully casts B to C" $       (cast b :: C) `shouldBe` c+#if __GLASGOW_HASKELL__ < 902+    it "successfully casts A to D" $+      (cast a :: D) `shouldBe` d     it "successfully casts B to D" $       (cast b :: D) `shouldBe` d-    it "successfully casts C to X" $-      (cast c :: X) `shouldBe` x-    it "successfully casts C to A" $-      (cast c :: A) `shouldBe` a-    it "successfully casts C to B" $-      (cast c :: B) `shouldBe` b     it "successfully casts C to D" $       (cast c :: D) `shouldBe` d     it "successfully casts D to D" $       (cast d :: D) `shouldBe` d     it "prefers the first element when casting D to D" $       (cast d' :: D) `shouldBe` d+    it "successfully casts E to D" $+      (cast e :: D) `shouldBe` d     it "successfully casts D to X" $       (cast d :: X) `shouldBe` x+#endif+    it "successfully casts C to X" $+      (cast c :: X) `shouldBe` x+    it "successfully casts C to A" $+      (cast c :: A) `shouldBe` a+    it "successfully casts C to B" $+      (cast c :: B) `shouldBe` b     it "successfully casts E to E" $       (cast e :: E) `shouldBe` e     it "successfully casts E to X" $       (cast e :: X) `shouldBe` x     it "successfully casts E to A" $       (cast e :: A) `shouldBe` a-    it "successfully casts E to D" $-      (cast e :: D) `shouldBe` d     it "correctly fails to cast A to B" $       shouldNotTypecheck (cast a :: B)     it "correctly fails to cast A to C" $       shouldNotTypecheck (cast a :: C)+#if __GLASGOW_HASKELL__ < 902     it "correctly fails to cast D to A" $       shouldNotTypecheck (cast d :: A)     it "correctly fails to cast D to B" $       shouldNotTypecheck (cast d :: B)     it "correctly fails to cast D to C" $       shouldNotTypecheck (cast d :: C)+#endif     it "correctly fails to cast E to B" $       shouldNotTypecheck (cast e :: B)     it "correctly fails to cast E to C" $@@ -164,13 +173,13 @@     -- The following two produce type errors as expected.     -- Unfortunately, user-defined type errors in combination     -- with shouldNotTypeCheck seems to trigger an internal-    -- error ... (see GHC bug #12104)-{-+    -- error ... (see GHC bug #12104) [fixed in 8.2]+#if __GLASGOW_HASKELL__ >= 802     it "fails to cast F to anything (even X)" $       shouldNotTypecheck (cast f :: X)     it "fails to cast G to anything (even X)" $       shouldNotTypecheck (cast g :: X)--}+#endif     it "successfully extracts anInt from A" $       getField @"anInt" a `shouldBe` 3     it "successfully extracts aBool from A" $@@ -189,5 +198,7 @@       getField @"aBool" c `shouldBe` True     it "successfully extracts aChar from C" $       getField @"aChar" c `shouldBe` 'x'+#if __GLASGOW_HASKELL__ < 902     it "successfully extracts the first anInt from D" $       getField @"anInt" d' `shouldBe` 3+#endif