packages feed

exinst-bytes 0.2 → 0.7

raw patch · 7 files changed

+450/−148 lines, 7 filesdep +QuickCheckdep +binarydep +bytestringdep ~basedep ~bytesdep ~constraintsPVP ok

version bump matches the API change (PVP)

Dependencies added: QuickCheck, binary, bytestring, cereal, exinst-bytes, exinst-cereal, tasty, tasty-quickcheck

Dependency ranges changed: base, bytes, constraints, exinst, singletons

API changes (from Hackage documentation)

- Exinst.Instances.Bytes: instance forall k1 (f1 :: k1 -> GHC.Types.*). (Data.Singletons.SingKind k1, Data.Bytes.Serial.Serial (Data.Singletons.DemoteRep k1), Exinst.Singletons.Dict1 Data.Bytes.Serial.Serial f1) => Data.Bytes.Serial.Serial (Exinst.Singletons.Some1 f1)
- Exinst.Instances.Bytes: instance forall k2 k1 (f2 :: k2 -> k1 -> GHC.Types.*). (Data.Singletons.SingKind k2, Data.Singletons.SingKind k1, Data.Bytes.Serial.Serial (Data.Singletons.DemoteRep k2), Data.Bytes.Serial.Serial (Data.Singletons.DemoteRep k1), Exinst.Singletons.Dict2 Data.Bytes.Serial.Serial f2) => Data.Bytes.Serial.Serial (Exinst.Singletons.Some2 f2)
- Exinst.Instances.Bytes: instance forall k3 k2 k1 (f3 :: k3 -> k2 -> k1 -> GHC.Types.*). (Data.Singletons.SingKind k3, Data.Singletons.SingKind k2, Data.Singletons.SingKind k1, Data.Bytes.Serial.Serial (Data.Singletons.DemoteRep k3), Data.Bytes.Serial.Serial (Data.Singletons.DemoteRep k2), Data.Bytes.Serial.Serial (Data.Singletons.DemoteRep k1), Exinst.Singletons.Dict3 Data.Bytes.Serial.Serial f3) => Data.Bytes.Serial.Serial (Exinst.Singletons.Some3 f3)
- Exinst.Instances.Bytes: instance forall k4 k3 k2 k1 (f4 :: k4 -> k3 -> k2 -> k1 -> GHC.Types.*). (Data.Singletons.SingKind k4, Data.Singletons.SingKind k3, Data.Singletons.SingKind k2, Data.Singletons.SingKind k1, Data.Bytes.Serial.Serial (Data.Singletons.DemoteRep k4), Data.Bytes.Serial.Serial (Data.Singletons.DemoteRep k3), Data.Bytes.Serial.Serial (Data.Singletons.DemoteRep k2), Data.Bytes.Serial.Serial (Data.Singletons.DemoteRep k1), Exinst.Singletons.Dict4 Data.Bytes.Serial.Serial f4) => Data.Bytes.Serial.Serial (Exinst.Singletons.Some4 f4)
+ Exinst.Bytes: instance forall k1 (f :: k1 -> *). (Data.Singletons.Internal.SingKind k1, Data.Bytes.Serial.Serial (Data.Singletons.Internal.Demote k1), Exinst.Internal.Dict1 Data.Bytes.Serial.Serial f) => Data.Bytes.Serial.Serial (Exinst.Internal.Some1 f)
+ Exinst.Bytes: instance forall k1 (l :: k1 -> *) (a1 :: k1) (r :: k1 -> *). (Data.Bytes.Serial.Serial (l a1), Data.Bytes.Serial.Serial (r a1)) => Data.Bytes.Serial.Serial (Exinst.Internal.Product.P1 l r a1)
+ Exinst.Bytes: instance forall k1 (l :: k1 -> *) (a1 :: k1) (r :: k1 -> *). (Data.Bytes.Serial.Serial (l a1), Data.Bytes.Serial.Serial (r a1)) => Data.Bytes.Serial.Serial (Exinst.Internal.Sum.S1 l r a1)
+ Exinst.Bytes: instance forall k2 k1 (f :: k2 -> k1 -> *). (Data.Singletons.Internal.SingKind k2, Data.Singletons.Internal.SingKind k1, Data.Bytes.Serial.Serial (Data.Singletons.Internal.Demote k2), Data.Bytes.Serial.Serial (Data.Singletons.Internal.Demote k1), Exinst.Internal.Dict2 Data.Bytes.Serial.Serial f) => Data.Bytes.Serial.Serial (Exinst.Internal.Some2 f)
+ Exinst.Bytes: instance forall k2 k1 (l :: k2 -> k1 -> *) (a2 :: k2) (a1 :: k1) (r :: k2 -> k1 -> *). (Data.Bytes.Serial.Serial (l a2 a1), Data.Bytes.Serial.Serial (r a2 a1)) => Data.Bytes.Serial.Serial (Exinst.Internal.Product.P2 l r a2 a1)
+ Exinst.Bytes: instance forall k2 k1 (l :: k2 -> k1 -> *) (a2 :: k2) (a1 :: k1) (r :: k2 -> k1 -> *). (Data.Bytes.Serial.Serial (l a2 a1), Data.Bytes.Serial.Serial (r a2 a1)) => Data.Bytes.Serial.Serial (Exinst.Internal.Sum.S2 l r a2 a1)
+ Exinst.Bytes: instance forall k3 k2 k1 (f :: k3 -> k2 -> k1 -> *). (Data.Singletons.Internal.SingKind k3, Data.Singletons.Internal.SingKind k2, Data.Singletons.Internal.SingKind k1, Data.Bytes.Serial.Serial (Data.Singletons.Internal.Demote k3), Data.Bytes.Serial.Serial (Data.Singletons.Internal.Demote k2), Data.Bytes.Serial.Serial (Data.Singletons.Internal.Demote k1), Exinst.Internal.Dict3 Data.Bytes.Serial.Serial f) => Data.Bytes.Serial.Serial (Exinst.Internal.Some3 f)
+ Exinst.Bytes: instance forall k3 k2 k1 (l :: k3 -> k2 -> k1 -> *) (a3 :: k3) (a2 :: k2) (a1 :: k1) (r :: k3 -> k2 -> k1 -> *). (Data.Bytes.Serial.Serial (l a3 a2 a1), Data.Bytes.Serial.Serial (r a3 a2 a1)) => Data.Bytes.Serial.Serial (Exinst.Internal.Product.P3 l r a3 a2 a1)
+ Exinst.Bytes: instance forall k3 k2 k1 (l :: k3 -> k2 -> k1 -> *) (a3 :: k3) (a2 :: k2) (a1 :: k1) (r :: k3 -> k2 -> k1 -> *). (Data.Bytes.Serial.Serial (l a3 a2 a1), Data.Bytes.Serial.Serial (r a3 a2 a1)) => Data.Bytes.Serial.Serial (Exinst.Internal.Sum.S3 l r a3 a2 a1)
+ Exinst.Bytes: instance forall k4 k3 k2 k1 (f :: k4 -> k3 -> k2 -> k1 -> *). (Data.Singletons.Internal.SingKind k4, Data.Singletons.Internal.SingKind k3, Data.Singletons.Internal.SingKind k2, Data.Singletons.Internal.SingKind k1, Data.Bytes.Serial.Serial (Data.Singletons.Internal.Demote k4), Data.Bytes.Serial.Serial (Data.Singletons.Internal.Demote k3), Data.Bytes.Serial.Serial (Data.Singletons.Internal.Demote k2), Data.Bytes.Serial.Serial (Data.Singletons.Internal.Demote k1), Exinst.Internal.Dict4 Data.Bytes.Serial.Serial f) => Data.Bytes.Serial.Serial (Exinst.Internal.Some4 f)
+ Exinst.Bytes: instance forall k4 k3 k2 k1 (l :: k4 -> k3 -> k2 -> k1 -> *) (a4 :: k4) (a3 :: k3) (a2 :: k2) (a1 :: k1) (r :: k4 -> k3 -> k2 -> k1 -> *). (Data.Bytes.Serial.Serial (l a4 a3 a2 a1), Data.Bytes.Serial.Serial (r a4 a3 a2 a1)) => Data.Bytes.Serial.Serial (Exinst.Internal.Product.P4 l r a4 a3 a2 a1)
+ Exinst.Bytes: instance forall k4 k3 k2 k1 (l :: k4 -> k3 -> k2 -> k1 -> *) (a4 :: k4) (a3 :: k3) (a2 :: k2) (a1 :: k1) (r :: k4 -> k3 -> k2 -> k1 -> *). (Data.Bytes.Serial.Serial (l a4 a3 a2 a1), Data.Bytes.Serial.Serial (r a4 a3 a2 a1)) => Data.Bytes.Serial.Serial (Exinst.Internal.Sum.S4 l r a4 a3 a2 a1)

Files

CHANGELOG.md view
@@ -1,18 +1,4 @@-# Version 0.2--* Depend on `singletons-2.2`, which means `KProxy` is gone.---# Version 0.1.0.2--* Relax upper bound on `base`, `singletons`, `constraints`.---# Version 0.1.0.1--* Relax upper bound on `singletons` dependency.---# Version 0.1+# Version 0.7 -* Initial release.+* This library exports the `Data.Bytes.Serial.Serial` instances+  previously exported from `exinst-0.6`.
LICENSE.txt view
@@ -1,4 +1,4 @@-Copyright (c) 2015-2016, Renzo Carbonara+Copyright (c) 2015-2018, Renzo Carbonara  All rights reserved. 
README.md view
@@ -1,2 +1,6 @@-See the README file in the @exinst@ package for more general documentation:-https://hackage.haskell.org/package/exinst#readme+# exinst-bytes++See the [BSD3 LICENSE](https://github.com/k0001/exinst/blob/master/exinst/exinst-bytes/LICENSE.txt)+file to learn about the legal terms and conditions for this library.++
exinst-bytes.cabal view
@@ -1,28 +1,48 @@ name:                exinst-bytes-version:             0.2+version:             0.7 author:              Renzo Carbonara-maintainer:          renzoλcarbonara.com.ar-copyright:           Renzo Carbonara 2015-2016+maintainer:          renλren!zone+copyright:           Renzo Carbonara 2015-2018 license:             BSD3 license-file:        LICENSE.txt extra-source-files:  README.md CHANGELOG.md category:            Data build-type:          Simple cabal-version:       >=1.18-synopsis:            Derive instances for the `bytes` library for your existential types.+synopsis:            Dependent pairs and their instances. homepage:            https://github.com/k0001/exinst bug-reports:         https://github.com/k0001/exinst/issues + library-  hs-source-dirs: src/lib+  hs-source-dirs: lib   default-language: Haskell2010-  exposed-modules:-      Exinst.Instances.Bytes+  exposed-modules: Exinst.Bytes   build-depends:       base >=4.9 && <5.0-    , bytes >=0.15 && <0.16-    , constraints >=0.4 && <0.9-    , exinst >=0.2 && <0.3-    , singletons >=2.2 && <2.3+    , bytes+    , constraints+    , exinst >=0.7+    , singletons   ghcjs-options: -Wall -O3   ghc-options: -Wall -O2++test-suite tests+  default-language: Haskell2010+  type: exitcode-stdio-1.0+  hs-source-dirs: tests+  main-is: Main.hs+  build-depends:+     base+   , binary+   , bytes+   , cereal+   , bytestring+   , exinst+   , exinst-bytes+   , exinst-cereal+   , QuickCheck+   , tasty+   , tasty-quickcheck+  ghcjs-options: -Wall -O0+  ghc-options: -Wall -O0
+ lib/Exinst/Bytes.hs view
@@ -0,0 +1,155 @@+{-# LANGUAGE DataKinds #-}+{-# LANGUAGE PolyKinds #-}+{-# LANGUAGE ScopedTypeVariables #-}+{-# LANGUAGE TypeInType #-}+{-# LANGUAGE UndecidableInstances #-}++{-# OPTIONS_GHC -fno-warn-orphans #-}++-- | This module exports 'By.Serial' instances for 'Some1', 'Some2', 'Some3'+-- and 'Some4' from "Exinst", provided situable 'Dict1', 'Dict2',+-- 'Dict3' and 'Dict4' instances are available.+--+-- See the README file in the @exinst@ package for more general documentation:+-- https://hackage.haskell.org/package/exinst#readme+module Exinst.Bytes () where++import qualified Data.Bytes.Serial as By+import Data.Constraint+import Data.Kind (Type)+import Data.Singletons+import Prelude++import Exinst++--------------------------------------------------------------------------------++-- | Compatible with the 'Data.Binary.Binary' instance and+-- 'Data.Serialize.Serialize' instance, provided all of the 'Demote's and the+-- fully applied @f@ instances are compatible as well.+instance forall (f :: k1 -> Type).+  ( SingKind k1+  , By.Serial (Demote k1)+  , Dict1 By.Serial f+  ) => By.Serial (Some1 f) where+  {-# INLINABLE serialize #-}+  serialize = \some1x ->+    withSome1Sing some1x $ \sa1 (x :: f a1) ->+      case dict1 sa1 :: Dict (By.Serial (f a1)) of+        Dict -> do+          By.serialize (fromSing sa1)+          By.serialize x+  {-# INLINABLE deserialize #-}+  deserialize = do+    rsa1 <- By.deserialize+    withSomeSing rsa1 $ \(sa1 :: Sing (a1 :: k1)) ->+      case dict1 sa1 :: Dict (By.Serial (f a1)) of+        Dict -> do+          x :: f a1 <- By.deserialize+          pure (Some1 sa1 x)++-- | Compatible with the 'Data.Binary.Binary' instance and+-- 'Data.Serialize.Serialize' instance, provided all of the 'Demote's and the+-- fully applied @f@ instances are compatible as well.+instance forall (f :: k2 -> k1 -> Type).+  ( SingKind k2+  , SingKind k1+  , By.Serial (Demote k2)+  , By.Serial (Demote k1)+  , Dict2 By.Serial f+  ) => By.Serial (Some2 f) where+  {-# INLINABLE serialize #-}+  serialize = \some2x ->+    withSome2Sing some2x $ \sa2 sa1 (x :: f a2 a1) ->+      case dict2 sa2 sa1 :: Dict (By.Serial (f a2 a1)) of+        Dict -> do+          By.serialize (fromSing sa2, fromSing sa1)+          By.serialize x+  {-# INLINABLE deserialize #-}+  deserialize = do+    (rsa2, rsa1) <- By.deserialize+    withSomeSing rsa2 $ \(sa2 :: Sing (a2 :: k2)) ->+      withSomeSing rsa1 $ \(sa1 :: Sing (a1 :: k1)) ->+        case dict2 sa2 sa1 :: Dict (By.Serial (f a2 a1)) of+          Dict -> do+            x :: f a2 a1 <- By.deserialize+            pure (Some2 sa2 sa1 x)++-- | Compatible with the 'Data.Binary.Binary' instance and+-- 'Data.Serialize.Serialize' instance, provided all of the 'Demote's and the+-- fully applied @f@ instances are compatible as well.+instance forall (f :: k3 -> k2 -> k1 -> Type).+  ( SingKind k3+  , SingKind k2+  , SingKind k1+  , By.Serial (Demote k3)+  , By.Serial (Demote k2)+  , By.Serial (Demote k1)+  , Dict3 By.Serial f+  ) => By.Serial (Some3 f) where+  {-# INLINABLE serialize #-}+  serialize = \some3x ->+    withSome3Sing some3x $ \sa3 sa2 sa1 (x :: f a3 a2 a1) ->+      case dict3 sa3 sa2 sa1 :: Dict (By.Serial (f a3 a2 a1)) of+        Dict -> do+          By.serialize (fromSing sa3, fromSing sa2, fromSing sa1)+          By.serialize x+  {-# INLINABLE deserialize #-}+  deserialize = do+    (rsa3, rsa2, rsa1) <- By.deserialize+    withSomeSing rsa3 $ \(sa3 :: Sing (a3 :: k3)) ->+      withSomeSing rsa2 $ \(sa2 :: Sing (a2 :: k2)) ->+        withSomeSing rsa1 $ \(sa1 :: Sing (a1 :: k1)) ->+           case dict3 sa3 sa2 sa1 :: Dict (By.Serial (f a3 a2 a1)) of+             Dict -> do+               x :: f a3 a2 a1 <- By.deserialize+               pure (Some3 sa3 sa2 sa1 x)++-- | Compatible with the 'Data.Binary.Binary' instance and+-- 'Data.Serialize.Serialize' instance, provided all of the 'Demote's and the+-- fully applied @f@ instances are compatible as well.+instance forall (f :: k4 -> k3 -> k2 -> k1 -> Type).+  ( SingKind k4+  , SingKind k3+  , SingKind k2+  , SingKind k1+  , By.Serial (Demote k4)+  , By.Serial (Demote k3)+  , By.Serial (Demote k2)+  , By.Serial (Demote k1)+  , Dict4 By.Serial f+  ) => By.Serial (Some4 f) where+  {-# INLINABLE serialize #-}+  serialize = \some4x ->+    withSome4Sing some4x $ \sa4 sa3 sa2 sa1 (x :: f a4 a3 a2 a1) ->+      case dict4 sa4 sa3 sa2 sa1 :: Dict (By.Serial (f a4 a3 a2 a1)) of+        Dict -> do+          By.serialize (fromSing sa4, fromSing sa3,+                        fromSing sa2, fromSing sa1)+          By.serialize x+  {-# INLINABLE deserialize #-}+  deserialize = do+    (rsa4, rsa3, rsa2, rsa1) <- By.deserialize+    withSomeSing rsa4 $ \(sa4 :: Sing (a4 :: k4)) ->+      withSomeSing rsa3 $ \(sa3 :: Sing (a3 :: k3)) ->+        withSomeSing rsa2 $ \(sa2 :: Sing (a2 :: k2)) ->+          withSomeSing rsa1 $ \(sa1 :: Sing (a1 :: k1)) ->+            case dict4 sa4 sa3 sa2 sa1 :: Dict (By.Serial (f a4 a3 a2 a1)) of+              Dict -> do+                x :: f a4 a3 a2 a1 <- By.deserialize+                pure (Some4 sa4 sa3 sa2 sa1 x)++--------------------------------------------------------------------------------++instance (By.Serial (l a1), By.Serial (r a1)) => By.Serial (S1 l r a1)+instance (By.Serial (l a2 a1), By.Serial (r a2 a1)) => By.Serial (S2 l r a2 a1)+instance (By.Serial (l a3 a2 a1), By.Serial (r a3 a2 a1)) => By.Serial (S3 l r a3 a2 a1)+instance (By.Serial (l a4 a3 a2 a1), By.Serial (r a4 a3 a2 a1)) => By.Serial (S4 l r a4 a3 a2 a1)++--------------------------------------------------------------------------------++instance (By.Serial (l a1), By.Serial (r a1)) => By.Serial (P1 l r a1)+instance (By.Serial (l a2 a1), By.Serial (r a2 a1)) => By.Serial (P2 l r a2 a1)+instance (By.Serial (l a3 a2 a1), By.Serial (r a3 a2 a1)) => By.Serial (P3 l r a3 a2 a1)+instance (By.Serial (l a4 a3 a2 a1), By.Serial (r a4 a3 a2 a1)) => By.Serial (P4 l r a4 a3 a2 a1)+
− src/lib/Exinst/Instances/Bytes.hs
@@ -1,117 +0,0 @@-{-# LANGUAGE DataKinds #-}-{-# LANGUAGE PolyKinds #-}-{-# LANGUAGE ScopedTypeVariables #-}-{-# LANGUAGE UndecidableInstances #-}--{-# OPTIONS_GHC -fno-warn-orphans #-}---- | This module exports 'By.Serial' instances for 'Some1', 'Some2', 'Some3'--- and 'Some4' from "Exinst.Singletons", provided situable 'Dict1', 'Dict2',--- 'Dict3' and 'Dict4' instances are available.------ See the README file in the @exinst@ package for more general documentation:--- https://hackage.haskell.org/package/exinst#readme-module Exinst.Instances.Bytes () where--import qualified Data.Bytes.Serial as By-import           Data.Constraint-import           Data.Singletons-import           Exinst.Singletons-import           Prelude------------------------------------------------------------------------------------instance forall (f1 :: k1 -> *)-  . ( SingKind k1-    , By.Serial (DemoteRep k1)-    , Dict1 By.Serial f1-    ) => By.Serial (Some1 f1)-  where-    {-# INLINABLE serialize #-}-    serialize = \some1x -> withSome1Sing some1x $ \sa1 (x :: f1 a1) ->-       case dict1 sa1 :: Dict (By.Serial (f1 a1)) of-          Dict -> do By.serialize (fromSing sa1)-                     By.serialize x-    {-# INLINABLE deserialize #-}-    deserialize = do-      rsa1 <- By.deserialize-      withSomeSing rsa1 $ \(sa1 :: Sing (a1 :: k1)) -> withSingI sa1 $-         case dict1 sa1 :: Dict (By.Serial (f1 a1)) of-            Dict -> do x :: f1 a1 <- By.deserialize-                       return (some1 x)--instance forall (f2 :: k2 -> k1 -> *)-  . ( SingKind k2-    , SingKind k1-    , By.Serial (DemoteRep k2)-    , By.Serial (DemoteRep k1)-    , Dict2 By.Serial f2-    ) => By.Serial (Some2 f2)-  where-    {-# INLINABLE serialize #-}-    serialize = \some2x -> withSome2Sing some2x $ \sa2 sa1 (x :: f2 a2 a1) ->-       case dict2 sa2 sa1 :: Dict (By.Serial (f2 a2 a1)) of-          Dict -> do By.serialize (fromSing sa2, fromSing sa1)-                     By.serialize x-    {-# INLINABLE deserialize #-}-    deserialize = do-      (rsa2, rsa1) <- By.deserialize-      withSomeSing rsa2 $ \(sa2 :: Sing (a2 :: k2)) -> withSingI sa2 $-         withSomeSing rsa1 $ \(sa1 :: Sing (a1 :: k1)) -> withSingI sa1 $-            case dict2 sa2 sa1 :: Dict (By.Serial (f2 a2 a1)) of-               Dict -> do x :: f2 a2 a1 <- By.deserialize-                          return (some2 x)--instance forall (f3 :: k3 -> k2 -> k1 -> *)-  . ( SingKind k3-    , SingKind k2-    , SingKind k1-    , By.Serial (DemoteRep k3)-    , By.Serial (DemoteRep k2)-    , By.Serial (DemoteRep k1)-    , Dict3 By.Serial f3-    ) => By.Serial (Some3 f3)-  where-    {-# INLINABLE serialize #-}-    serialize = \some3x -> withSome3Sing some3x $ \sa3 sa2 sa1 (x :: f3 a3 a2 a1) ->-       case dict3 sa3 sa2 sa1 :: Dict (By.Serial (f3 a3 a2 a1)) of-          Dict -> do By.serialize (fromSing sa3, fromSing sa2, fromSing sa1)-                     By.serialize x-    {-# INLINABLE deserialize #-}-    deserialize = do-      (rsa3, rsa2, rsa1) <- By.deserialize-      withSomeSing rsa3 $ \(sa3 :: Sing (a3 :: k3)) -> withSingI sa3 $-         withSomeSing rsa2 $ \(sa2 :: Sing (a2 :: k2)) -> withSingI sa2 $-            withSomeSing rsa1 $ \(sa1 :: Sing (a1 :: k1)) -> withSingI sa1 $-               case dict3 sa3 sa2 sa1 :: Dict (By.Serial (f3 a3 a2 a1)) of-                  Dict -> do x :: f3 a3 a2 a1 <- By.deserialize-                             return (some3 x)--instance forall (f4 :: k4 -> k3 -> k2 -> k1 -> *)-  . ( SingKind k4-    , SingKind k3-    , SingKind k2-    , SingKind k1-    , By.Serial (DemoteRep k4)-    , By.Serial (DemoteRep k3)-    , By.Serial (DemoteRep k2)-    , By.Serial (DemoteRep k1)-    , Dict4 By.Serial f4-    ) => By.Serial (Some4 f4)-  where-    {-# INLINABLE serialize #-}-    serialize = \some4x -> withSome4Sing some4x $ \sa4 sa3 sa2 sa1 (x :: f4 a4 a3 a2 a1) ->-       case dict4 sa4 sa3 sa2 sa1 :: Dict (By.Serial (f4 a4 a3 a2 a1)) of-          Dict -> do By.serialize (fromSing sa4, fromSing sa3,-                                   fromSing sa2, fromSing sa1)-                     By.serialize x-    {-# INLINABLE deserialize #-}-    deserialize = do-      (rsa4, rsa3, rsa2, rsa1) <- By.deserialize-      withSomeSing rsa4 $ \(sa4 :: Sing (a4 :: k4)) -> withSingI sa4 $-         withSomeSing rsa3 $ \(sa3 :: Sing (a3 :: k3)) -> withSingI sa3 $-            withSomeSing rsa2 $ \(sa2 :: Sing (a2 :: k2)) -> withSingI sa2 $-               withSomeSing rsa1 $ \(sa1 :: Sing (a1 :: k1)) -> withSingI sa1 $-                  case dict4 sa4 sa3 sa2 sa1 :: Dict (By.Serial (f4 a4 a3 a2 a1)) of-                     Dict -> do x :: f4 a4 a3 a2 a1 <- By.deserialize-                                return (some4 x)
+ tests/Main.hs view
@@ -0,0 +1,254 @@+{-# LANGUAGE CPP #-}+{-# LANGUAGE ConstraintKinds #-}+{-# LANGUAGE DataKinds #-}+{-# LANGUAGE DeriveAnyClass #-}+{-# LANGUAGE DeriveGeneric #-}+{-# LANGUAGE FlexibleInstances #-}+{-# LANGUAGE RankNTypes #-}+{-# LANGUAGE ScopedTypeVariables #-}+{-# LANGUAGE TypeFamilies #-}++module Main where++import qualified Data.Binary as Bin+import qualified Data.Bytes.Get as Bytes+import qualified Data.Bytes.Put as Bytes+import qualified Data.Bytes.Serial as Bytes+import qualified Data.ByteString.Lazy as BSL+import Data.Int (Int32)+import Data.Kind (Type)+import qualified Data.Serialize as Cer+import qualified GHC.Generics as G+import qualified Test.Tasty as Tasty+import qualified Test.Tasty.Runners as Tasty+import Test.Tasty.QuickCheck ((===))+import qualified Test.Tasty.QuickCheck as QC++import Exinst+import Exinst.Bytes ()+import Exinst.Cereal ()++--------------------------------------------------------------------------------++main :: IO ()+main = Tasty.defaultMainWithIngredients+  [ Tasty.consoleTestReporter+  , Tasty.listingTests+  ] tt++--------------------------------------------------------------------------------++data family X1 :: Bool -> Type+data instance X1 'False = XF1 | XF2 Int32 deriving (Eq, Show, Read, G.Generic, Bin.Binary)+data instance X1 'True = XT1 | XT2 Int32 deriving (Eq, Show, Read, G.Generic, Bin.Binary)++data family X2 :: Bool -> Bool -> Type+data instance X2 'False 'False = XFF1 | XFF2 Int32 deriving (Eq, Show, Read, G.Generic, Bin.Binary)+data instance X2 'False 'True = XFT1 | XFT2 Int32 deriving (Eq, Show, Read, G.Generic, Bin.Binary)+data instance X2 'True 'False = XTF1 | XTF2 Int32 deriving (Eq, Show, Read, G.Generic, Bin.Binary)+data instance X2 'True 'True = XTT1 | XTT2 Int32 deriving (Eq, Show, Read, G.Generic, Bin.Binary)++data family X3 :: Bool -> Bool -> Bool -> Type+data instance X3 'False 'False 'False = XFFF1 | XFFF2 Int32 deriving (Eq, Show, Read, G.Generic, Bin.Binary)+data instance X3 'False 'False 'True = XFFT1 | XFFT2 Int32 deriving (Eq, Show, Read, G.Generic, Bin.Binary)+data instance X3 'False 'True 'False = XFTF1 | XFTF2 Int32 deriving (Eq, Show, Read, G.Generic, Bin.Binary)+data instance X3 'False 'True 'True = XFTT1 | XFTT2 Int32 deriving (Eq, Show, Read, G.Generic, Bin.Binary)+data instance X3 'True 'False 'False = XTFF1 | XTFF2 Int32 deriving (Eq, Show, Read, G.Generic, Bin.Binary)+data instance X3 'True 'False 'True = XTFT1 | XTFT2 Int32 deriving (Eq, Show, Read, G.Generic, Bin.Binary)+data instance X3 'True 'True 'False = XTTF1 | XTTF2 Int32 deriving (Eq, Show, Read, G.Generic, Bin.Binary)+data instance X3 'True 'True 'True = XTTT1 | XTTT2 Int32 deriving (Eq, Show, Read, G.Generic, Bin.Binary)++data family X4 :: Bool -> Bool -> Bool -> Bool -> Type+data instance X4 'False 'False 'False 'False = XFFFF1 | XFFFF2 Int32 deriving (Eq, Show, Read, G.Generic, Bin.Binary)+data instance X4 'False 'False 'False 'True = XFFFT1 | XFFFT2 Int32 deriving (Eq, Show, Read, G.Generic, Bin.Binary)+data instance X4 'False 'False 'True 'False = XFFTF1 | XFFTF2 Int32 deriving (Eq, Show, Read, G.Generic, Bin.Binary)+data instance X4 'False 'False 'True 'True = XFFTT1 | XFFTT2 Int32 deriving (Eq, Show, Read, G.Generic, Bin.Binary)+data instance X4 'False 'True 'False 'False = XFTFF1 | XFTFF2 Int32 deriving (Eq, Show, Read, G.Generic, Bin.Binary)+data instance X4 'False 'True 'False 'True = XFTFT1 | XFTFT2 Int32 deriving (Eq, Show, Read, G.Generic, Bin.Binary)+data instance X4 'False 'True 'True 'False = XFTTF1 | XFTTF2 Int32 deriving (Eq, Show, Read, G.Generic, Bin.Binary)+data instance X4 'False 'True 'True 'True = XFTTT1 | XFTTT2 Int32 deriving (Eq, Show, Read, G.Generic, Bin.Binary)+data instance X4 'True 'False 'False 'False = XTFFF1 | XTFFF2 Int32 deriving (Eq, Show, Read, G.Generic, Bin.Binary)+data instance X4 'True 'False 'False 'True = XTFFT1 | XTFFT2 Int32 deriving (Eq, Show, Read, G.Generic, Bin.Binary)+data instance X4 'True 'False 'True 'False = XTFTF1 | XTFTF2 Int32 deriving (Eq, Show, Read, G.Generic, Bin.Binary)+data instance X4 'True 'False 'True 'True = XTFTT1 | XTFTT2 Int32 deriving (Eq, Show, Read, G.Generic, Bin.Binary)+data instance X4 'True 'True 'False 'False = XTTFF1 | XTTFF2 Int32 deriving (Eq, Show, Read, G.Generic, Bin.Binary)+data instance X4 'True 'True 'False 'True = XTTFT1 | XTTFT2 Int32 deriving (Eq, Show, Read, G.Generic, Bin.Binary)+data instance X4 'True 'True 'True 'False = XTTTF1 | XTTTF2 Int32 deriving (Eq, Show, Read, G.Generic, Bin.Binary)+data instance X4 'True 'True 'True 'True = XTTTT1 | XTTTT2 Int32 deriving (Eq, Show, Read, G.Generic, Bin.Binary)++#define INSTANCETRON(c) \+  instance c (X1 'False); \+  instance c (X1 'True); \+  instance c (X2 'False 'False); \+  instance c (X2 'False 'True); \+  instance c (X2 'True 'False); \+  instance c (X2 'True 'True); \+  instance c (X3 'False 'False 'False); \+  instance c (X3 'False 'False 'True); \+  instance c (X3 'False 'True 'False); \+  instance c (X3 'False 'True 'True); \+  instance c (X3 'True 'False 'False); \+  instance c (X3 'True 'False 'True); \+  instance c (X3 'True 'True 'False); \+  instance c (X3 'True 'True 'True); \+  instance c (X4 'False 'False 'False 'False); \+  instance c (X4 'False 'False 'False 'True); \+  instance c (X4 'False 'False 'True 'False); \+  instance c (X4 'False 'False 'True 'True); \+  instance c (X4 'False 'True 'False 'False); \+  instance c (X4 'False 'True 'False 'True); \+  instance c (X4 'False 'True 'True 'False); \+  instance c (X4 'False 'True 'True 'True); \+  instance c (X4 'True 'False 'False 'False); \+  instance c (X4 'True 'False 'False 'True); \+  instance c (X4 'True 'False 'True 'False); \+  instance c (X4 'True 'False 'True 'True); \+  instance c (X4 'True 'True 'False 'False); \+  instance c (X4 'True 'True 'False 'True); \+  instance c (X4 'True 'True 'True 'False); \+  instance c (X4 'True 'True 'True 'True)++--------------------------------------------------------------------------------+-- Arbitrary instances++instance QC.Arbitrary (X1 'False) where arbitrary = QC.oneof [ pure XF1, fmap XF2 QC.arbitrary ]+instance QC.Arbitrary (X1 'True) where arbitrary = QC.oneof [ pure XT1, fmap XT2 QC.arbitrary ]++instance QC.Arbitrary (X2 'False 'False) where arbitrary = QC.oneof [ pure XFF1, fmap XFF2 QC.arbitrary ]+instance QC.Arbitrary (X2 'False 'True) where arbitrary = QC.oneof [ pure XFT1, fmap XFT2 QC.arbitrary ]+instance QC.Arbitrary (X2 'True 'False) where arbitrary = QC.oneof [ pure XTF1, fmap XTF2 QC.arbitrary ]+instance QC.Arbitrary (X2 'True 'True) where arbitrary = QC.oneof [ pure XTT1, fmap XTT2 QC.arbitrary ]++instance QC.Arbitrary (X3 'False 'False 'False) where arbitrary = QC.oneof [ pure XFFF1, fmap XFFF2 QC.arbitrary ]+instance QC.Arbitrary (X3 'False 'False 'True) where arbitrary = QC.oneof [ pure XFFT1, fmap XFFT2 QC.arbitrary ]+instance QC.Arbitrary (X3 'False 'True 'False) where arbitrary = QC.oneof [ pure XFTF1, fmap XFTF2 QC.arbitrary ]+instance QC.Arbitrary (X3 'False 'True 'True) where arbitrary = QC.oneof [ pure XFTT1, fmap XFTT2 QC.arbitrary ]+instance QC.Arbitrary (X3 'True 'False 'False) where arbitrary = QC.oneof [ pure XTFF1, fmap XTFF2 QC.arbitrary ]+instance QC.Arbitrary (X3 'True 'False 'True) where arbitrary = QC.oneof [ pure XTFT1, fmap XTFT2 QC.arbitrary ]+instance QC.Arbitrary (X3 'True 'True 'False) where arbitrary = QC.oneof [ pure XTTF1, fmap XTTF2 QC.arbitrary ]+instance QC.Arbitrary (X3 'True 'True 'True) where arbitrary = QC.oneof [ pure XTTT1, fmap XTTT2 QC.arbitrary ]++instance QC.Arbitrary (X4 'False 'False 'False 'False) where arbitrary = QC.oneof [ pure XFFFF1, fmap XFFFF2 QC.arbitrary ]+instance QC.Arbitrary (X4 'False 'False 'False 'True) where arbitrary = QC.oneof [ pure XFFFT1, fmap XFFFT2 QC.arbitrary ]+instance QC.Arbitrary (X4 'False 'False 'True 'False) where arbitrary = QC.oneof [ pure XFFTF1, fmap XFFTF2 QC.arbitrary ]+instance QC.Arbitrary (X4 'False 'False 'True 'True) where arbitrary = QC.oneof [ pure XFFTT1, fmap XFFTT2 QC.arbitrary ]+instance QC.Arbitrary (X4 'False 'True 'False 'False) where arbitrary = QC.oneof [ pure XFTFF1, fmap XFTFF2 QC.arbitrary ]+instance QC.Arbitrary (X4 'False 'True 'False 'True) where arbitrary = QC.oneof [ pure XFTFT1, fmap XFTFT2 QC.arbitrary ]+instance QC.Arbitrary (X4 'False 'True 'True 'False) where arbitrary = QC.oneof [ pure XFTTF1, fmap XFTTF2 QC.arbitrary ]+instance QC.Arbitrary (X4 'False 'True 'True 'True) where arbitrary = QC.oneof [ pure XFTTT1, fmap XFTTT2 QC.arbitrary ]+instance QC.Arbitrary (X4 'True 'False 'False 'False) where arbitrary = QC.oneof [ pure XTFFF1, fmap XTFFF2 QC.arbitrary ]+instance QC.Arbitrary (X4 'True 'False 'False 'True) where arbitrary = QC.oneof [ pure XTFFT1, fmap XTFFT2 QC.arbitrary ]+instance QC.Arbitrary (X4 'True 'False 'True 'False) where arbitrary = QC.oneof [ pure XTFTF1, fmap XTFTF2 QC.arbitrary ]+instance QC.Arbitrary (X4 'True 'False 'True 'True) where arbitrary = QC.oneof [ pure XTFTT1, fmap XTFTT2 QC.arbitrary ]+instance QC.Arbitrary (X4 'True 'True 'False 'False) where arbitrary = QC.oneof [ pure XTTFF1, fmap XTTFF2 QC.arbitrary ]+instance QC.Arbitrary (X4 'True 'True 'False 'True) where arbitrary = QC.oneof [ pure XTTFT1, fmap XTTFT2 QC.arbitrary ]+instance QC.Arbitrary (X4 'True 'True 'True 'False) where arbitrary = QC.oneof [ pure XTTTF1, fmap XTTTF2 QC.arbitrary ]+instance QC.Arbitrary (X4 'True 'True 'True 'True) where arbitrary = QC.oneof [ pure XTTTT1, fmap XTTTT2 QC.arbitrary ]++--------------------------------------------------------------------------------++tt :: Tasty.TestTree+tt =+  Tasty.testGroup "main"+  [ tt_id "Identity through Bytes's Serial" id_bytes+  , tt_id "Identity from Binary's Binary to Bytes's Serial" id_binary_to_bytes+  , tt_id "Identity from Bytes's Serial to Binary's Binary" id_bytes_to_binary+  , tt_id "Identity from Cereal's Serialize to Bytes's Serial" id_cereal_to_bytes+  , tt_id "Identity from Bytes's Serial to Cereal's Serialize" id_bytes_to_cereal+  , tt_id "Identity through Cereal's Serialize" id_cereal+  , tt_id "Identity from Binary's Binary to Cereal's Serialize" id_binary_to_cereal+  , tt_id "Identity from Cereal's Serialize to Binary's Binary" id_cereal_to_binary+  ]++type MegaCtx a = (Bin.Binary a, Bytes.Serial a, Cer.Serialize a)++tt_id+  :: String+  -> (forall a. MegaCtx a => a -> Maybe a)+  -- ^ It's easier to put all the constraints here in the 'MegaCtx' monster.+  -> Tasty.TestTree+tt_id = \title id' -> Tasty.testGroup title+  [ QC.testProperty "Some1 X1" $+      QC.forAll QC.arbitrary $ \(x :: Some1 X1) -> Just x === id' x+  , QC.testProperty "Some2 X2" $+      QC.forAll QC.arbitrary $ \(x :: Some2 X2) -> Just x === id' x+  , QC.testProperty "Some3 X3" $+      QC.forAll QC.arbitrary $ \(x :: Some3 X3) -> Just x === id' x+  , QC.testProperty "Some4 X4" $+      QC.forAll QC.arbitrary $ \(x :: Some4 X4) -> Just x === id' x+  , QC.testProperty "Some1 (P1 X1 X1)" $+      QC.forAll QC.arbitrary $ \(x :: Some1 (P1 X1 X1)) -> Just x === id' x+  , QC.testProperty "Some2 (P2 X2 X2)" $+      QC.forAll QC.arbitrary $ \(x :: Some2 (P2 X2 X2)) -> Just x === id' x+  , QC.testProperty "Some3 (P3 X3 X3)" $+      QC.forAll QC.arbitrary $ \(x :: Some3 (P3 X3 X3)) -> Just x === id' x+  , QC.testProperty "Some4 (P4 X4 X4)" $+      QC.forAll QC.arbitrary $ \(x :: Some4 (P4 X4 X4)) -> Just x === id' x+  , QC.testProperty "Some1 (S1 X1 X1)" $+      QC.forAll QC.arbitrary $ \(x :: Some1 (S1 X1 X1)) -> Just x === id' x+  , QC.testProperty "Some2 (S2 X2 X2)" $+      QC.forAll QC.arbitrary $ \(x :: Some2 (S2 X2 X2)) -> Just x === id' x+  , QC.testProperty "Some3 (S3 X3 X3)" $+      QC.forAll QC.arbitrary $ \(x :: Some3 (S3 X3 X3)) -> Just x === id' x+  , QC.testProperty "Some4 (S4 X4 X4)" $+      QC.forAll QC.arbitrary $ \(x :: Some4 (S4 X4 X4)) -> Just x === id' x+  ]++--------------------------------------------------------------------------------++INSTANCETRON(Bytes.Serial)+id_bytes :: Bytes.Serial a => a -> Maybe a+id_bytes = \a ->+  case Bytes.runGetS Bytes.deserialize (Bytes.runPutS (Bytes.serialize a)) of+     Left _ -> Nothing+     Right a' -> Just a'++id_binary_to_bytes :: (Bin.Binary a, Bytes.Serial a) => a -> Maybe a+id_binary_to_bytes = \a ->+   case Bytes.runGetS Bytes.deserialize (BSL.toStrict (Bin.encode a)) of+     Left _ -> Nothing+     Right a' -> Just a'++id_bytes_to_binary :: (Bytes.Serial a, Bin.Binary a) => a -> Maybe a+id_bytes_to_binary = \a ->+   case Bin.decodeOrFail (Bytes.runPutL (Bytes.serialize a)) of+      Right (z,_,a') | BSL.null z -> Just a'+      _ -> Nothing++id_binary :: Bin.Binary a => a -> Maybe a+id_binary = \a ->+  case Bin.decodeOrFail (Bin.encode a) of+      Right (z,_,a') | BSL.null z -> Just a'+      _ -> Nothing++INSTANCETRON(Cer.Serialize)+id_cereal :: Cer.Serialize a => a -> Maybe a+id_cereal = \a ->+  case Cer.decodeLazy (Cer.encodeLazy a) of+     Right a' -> Just a'+     Left _ -> Nothing++id_binary_to_cereal :: (Bin.Binary a, Cer.Serialize a) => a -> Maybe a+id_binary_to_cereal = \a ->+  case Cer.decodeLazy (Bin.encode a) of+     Right a' -> Just a'+     Left _ -> Nothing++id_cereal_to_binary :: (Bin.Binary a, Cer.Serialize a) => a -> Maybe a+id_cereal_to_binary = \a ->+   case Bin.decodeOrFail (Cer.encodeLazy a) of+      Right (z,_,a') | BSL.null z -> Just a'+      _ -> Nothing++id_cereal_to_bytes :: (Cer.Serialize a, Bytes.Serial a) => a -> Maybe a+id_cereal_to_bytes = \a ->+   case Bytes.runGetS Bytes.deserialize (Cer.encode a) of+     Left _ -> Nothing+     Right a' -> Just a'++id_bytes_to_cereal :: (Bytes.Serial a, Cer.Serialize a) => a -> Maybe a+id_bytes_to_cereal = \a ->+  case Cer.decodeLazy (Bytes.runPutL (Bytes.serialize a)) of+     Right a' -> Just a'+     Left _ -> Nothing+