{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE DataKinds #-}
module Data.TypedEncoding (
Enc
, toEncoding
, fromEncoding
, getPayload
, module Data.TypedEncoding.Common.Types.CheckedEnc
, Encoding (..)
, _mkEncoding
, _mkEncoding1
, runEncoding'
, _runEncoding
, runEncoding1'
, Encodings (..)
, runEncodings'
, _runEncodings
, module Data.TypedEncoding.Common.Types.Decoding
, module Data.TypedEncoding.Common.Types.Validation
, module Data.TypedEncoding.Common.Types.UncheckedEnc
, propSafeDecoding'
, _propSafeDecoding
, propSafeValidatedDecoding'
, _propSafeValidatedDecoding
, Encode (..)
, EncodeAll (..)
, module Data.TypedEncoding.Common.Class
, module Data.TypedEncoding.Combinators.Common
, module Data.TypedEncoding.Combinators.Encode
, module Data.TypedEncoding.Combinators.Decode
, module Data.TypedEncoding.Combinators.Validate
, module Data.TypedEncoding.Combinators.Unsafe
, module Data.TypedEncoding.Combinators.ToEncStr
, module Data.TypedEncoding.Combinators.Promotion
, module Data.TypedEncoding.Common.Types.Exceptions
, module Data.TypedEncoding.Common.Types.Common
) where
import Data.TypedEncoding.Common.Types.Enc
import Data.TypedEncoding.Common.Types.Decoding
import Data.TypedEncoding.Common.Types.Validation
import Data.TypedEncoding.Common.Types.Common
import Data.TypedEncoding.Common.Types.CheckedEnc
import Data.TypedEncoding.Common.Types.UncheckedEnc
import Data.TypedEncoding.Common.Types.Exceptions
import Data.TypedEncoding.Common.Class
import Data.TypedEncoding.Combinators.Common
import Data.TypedEncoding.Combinators.Encode
import Data.TypedEncoding.Combinators.Decode
import Data.TypedEncoding.Combinators.Validate
import Data.TypedEncoding.Combinators.Unsafe
import Data.TypedEncoding.Combinators.ToEncStr
import Data.TypedEncoding.Combinators.Promotion
propSafeDecoding' :: forall alg nm c str. (Eq c, Eq str) =>
Encoding (Either EncodeEx) nm alg c str
-> Decoding (Either UnexpectedDecodeEx) nm alg c str
-> c
-> str
-> Bool
propSafeDecoding' :: Encoding (Either EncodeEx) nm alg c str
-> Decoding (Either UnexpectedDecodeEx) nm alg c str
-> c
-> str
-> Bool
propSafeDecoding' Encoding (Either EncodeEx) nm alg c str
encf Decoding (Either UnexpectedDecodeEx) nm alg c str
decf c
c str
str = Enc @[Symbol] ('[] @Symbol) c str
-> Either String (Enc @[Symbol] ('[] @Symbol) c str)
forall a b. b -> Either a b
Right Enc @[Symbol] ('[] @Symbol) c str
enc0 Either String (Enc @[Symbol] ('[] @Symbol) c str)
-> Either String (Enc @[Symbol] ('[] @Symbol) c str) -> Bool
forall a. Eq a => a -> a -> Bool
== Either String (Enc @[Symbol] ('[] @Symbol) c str)
edec
where
enc0 :: Enc @[Symbol] ('[] @Symbol) c str
enc0 = c -> str -> Enc @[Symbol] ('[] @Symbol) c str
forall conf str.
conf -> str -> Enc @[Symbol] ('[] @Symbol) conf str
toEncoding c
c str
str
eenc :: Either
EncodeEx (Enc @[Symbol] ((':) @Symbol nm ('[] @Symbol)) c str)
eenc = Encoding (Either EncodeEx) nm alg c str
-> Enc @[Symbol] ('[] @Symbol) c str
-> Either
EncodeEx (Enc @[Symbol] ((':) @Symbol nm ('[] @Symbol)) c str)
forall (alg :: Symbol) (nm :: Symbol) (f :: * -> *)
(xs :: [Symbol]) conf str.
Encoding f nm alg conf str
-> Enc @[Symbol] xs conf str
-> f (Enc @[Symbol] ((':) @Symbol nm xs) conf str)
runEncoding' @alg Encoding (Either EncodeEx) nm alg c str
encf Enc @[Symbol] ('[] @Symbol) c str
enc0
edec :: Either String (Enc @[Symbol] ('[] @Symbol) c str)
edec = case Either
EncodeEx (Enc @[Symbol] ((':) @Symbol nm ('[] @Symbol)) c str)
eenc of
Right Enc @[Symbol] ((':) @Symbol nm ('[] @Symbol)) c str
enc -> (UnexpectedDecodeEx
-> Either String (Enc @[Symbol] ('[] @Symbol) c str))
-> (Enc @[Symbol] ('[] @Symbol) c str
-> Either String (Enc @[Symbol] ('[] @Symbol) c str))
-> Either UnexpectedDecodeEx (Enc @[Symbol] ('[] @Symbol) c str)
-> Either String (Enc @[Symbol] ('[] @Symbol) c str)
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either (String -> Either String (Enc @[Symbol] ('[] @Symbol) c str)
forall a b. a -> Either a b
Left (String -> Either String (Enc @[Symbol] ('[] @Symbol) c str))
-> (UnexpectedDecodeEx -> String)
-> UnexpectedDecodeEx
-> Either String (Enc @[Symbol] ('[] @Symbol) c str)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. UnexpectedDecodeEx -> String
forall a. Show a => a -> String
show) Enc @[Symbol] ('[] @Symbol) c str
-> Either String (Enc @[Symbol] ('[] @Symbol) c str)
forall a b. b -> Either a b
Right (Either UnexpectedDecodeEx (Enc @[Symbol] ('[] @Symbol) c str)
-> Either String (Enc @[Symbol] ('[] @Symbol) c str))
-> Either UnexpectedDecodeEx (Enc @[Symbol] ('[] @Symbol) c str)
-> Either String (Enc @[Symbol] ('[] @Symbol) c str)
forall a b. (a -> b) -> a -> b
$ Decoding (Either UnexpectedDecodeEx) nm alg c str
-> Enc @[Symbol] ((':) @Symbol nm ('[] @Symbol)) c str
-> Either UnexpectedDecodeEx (Enc @[Symbol] ('[] @Symbol) c str)
forall (alg :: Symbol) (nm :: Symbol) (f :: * -> *)
(xs :: [Symbol]) conf str.
Decoding f nm alg conf str
-> Enc @[Symbol] ((':) @Symbol nm xs) conf str
-> f (Enc @[Symbol] xs conf str)
runDecoding' @alg Decoding (Either UnexpectedDecodeEx) nm alg c str
decf Enc @[Symbol] ((':) @Symbol nm ('[] @Symbol)) c str
enc
Left EncodeEx
enc -> Enc @[Symbol] ('[] @Symbol) c str
-> Either String (Enc @[Symbol] ('[] @Symbol) c str)
forall a b. b -> Either a b
Right Enc @[Symbol] ('[] @Symbol) c str
enc0
_propSafeDecoding :: forall nm c str alg . (Algorithm nm alg, Eq c, Eq str) =>
Encoding (Either EncodeEx) nm alg c str
-> Decoding (Either UnexpectedDecodeEx) nm alg c str
-> c
-> str
-> Bool
_propSafeDecoding :: Encoding (Either EncodeEx) nm alg c str
-> Decoding (Either UnexpectedDecodeEx) nm alg c str
-> c
-> str
-> Bool
_propSafeDecoding = forall (nm :: Symbol) c str.
(Eq c, Eq str) =>
Encoding (Either EncodeEx) nm (AlgNm nm) c str
-> Decoding (Either UnexpectedDecodeEx) nm (AlgNm nm) c str
-> c
-> str
-> Bool
forall (alg :: Symbol) (nm :: Symbol) c str.
(Eq c, Eq str) =>
Encoding (Either EncodeEx) nm alg c str
-> Decoding (Either UnexpectedDecodeEx) nm alg c str
-> c
-> str
-> Bool
propSafeDecoding' @(AlgNm nm)
propSafeValidatedDecoding' :: forall alg nm c str. (Eq c, Eq str) =>
Validation (Either RecreateEx) nm alg c str
-> Decoding (Either UnexpectedDecodeEx) nm alg c str
-> c
-> str
-> Bool
propSafeValidatedDecoding' :: Validation (Either RecreateEx) nm alg c str
-> Decoding (Either UnexpectedDecodeEx) nm alg c str
-> c
-> str
-> Bool
propSafeValidatedDecoding' Validation (Either RecreateEx) nm alg c str
validf Decoding (Either UnexpectedDecodeEx) nm alg c str
decf c
c str
str = Either String str
edec Either String str -> Either String str -> Bool
forall a. Eq a => a -> a -> Bool
== Either String str
echeck
where
enc0 :: Enc @[Symbol] ('[] @Symbol) c str
enc0 = c -> str -> Enc @[Symbol] ('[] @Symbol) c str
forall conf str.
conf -> str -> Enc @[Symbol] ('[] @Symbol) conf str
toEncoding c
c str
str
valfs :: Validations
(Either RecreateEx)
((':) @Symbol nm ('[] @Symbol))
((':) @Symbol alg ('[] @Symbol))
c
str
valfs = Validation (Either RecreateEx) nm alg c str
validf Validation (Either RecreateEx) nm alg c str
-> Validations
(Either RecreateEx) ('[] @Symbol) ('[] @Symbol) c str
-> Validations
(Either RecreateEx)
((':) @Symbol nm ('[] @Symbol))
((':) @Symbol alg ('[] @Symbol))
c
str
forall (f :: * -> *) (nm :: Symbol) (alg :: Symbol) conf str
(nms :: [Symbol]) (algs :: [Symbol]).
Validation f nm alg conf str
-> Validations f nms algs conf str
-> Validations
f ((':) @Symbol nm nms) ((':) @Symbol alg algs) conf str
`ConsV` Validations (Either RecreateEx) ('[] @Symbol) ('[] @Symbol) c str
forall (f :: * -> *) conf str.
Validations f ('[] @Symbol) ('[] @Symbol) conf str
ZeroV
eenc :: Either
RecreateEx (Enc @[Symbol] ((':) @Symbol nm ('[] @Symbol)) c str)
eenc = Validations
(Either RecreateEx)
((':) @Symbol nm ('[] @Symbol))
((':) @Symbol alg ('[] @Symbol))
c
str
-> Enc @[Symbol] ('[] @Symbol) c str
-> Either
RecreateEx (Enc @[Symbol] ((':) @Symbol nm ('[] @Symbol)) c str)
forall (algs :: [Symbol]) (nms :: [Symbol]) (f :: * -> *) c str.
Monad f =>
Validations f nms algs c str
-> Enc @[Symbol] ('[] @Symbol) c str -> f (Enc @[Symbol] nms c str)
recreateWithValidations @'[alg] @'[nm] Validations
(Either RecreateEx)
((':) @Symbol nm ('[] @Symbol))
((':) @Symbol alg ('[] @Symbol))
c
str
valfs Enc @[Symbol] ('[] @Symbol) c str
enc0
(Either String str
edec :: Either String str, Either String str
echeck :: Either String str) = case Either
RecreateEx (Enc @[Symbol] ((':) @Symbol nm ('[] @Symbol)) c str)
eenc of
Right Enc @[Symbol] ((':) @Symbol nm ('[] @Symbol)) c str
enc -> ((UnexpectedDecodeEx -> Either String str)
-> (Enc @[Symbol] ('[] @Symbol) c str -> Either String str)
-> Either UnexpectedDecodeEx (Enc @[Symbol] ('[] @Symbol) c str)
-> Either String str
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either (String -> Either String str
forall a b. a -> Either a b
Left (String -> Either String str)
-> (UnexpectedDecodeEx -> String)
-> UnexpectedDecodeEx
-> Either String str
forall b c a. (b -> c) -> (a -> b) -> a -> c
. UnexpectedDecodeEx -> String
forall a. Show a => a -> String
show) (str -> Either String str
forall a b. b -> Either a b
Right (str -> Either String str)
-> (Enc @[Symbol] ('[] @Symbol) c str -> str)
-> Enc @[Symbol] ('[] @Symbol) c str
-> Either String str
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Enc @[Symbol] ('[] @Symbol) c str -> str
forall k (enc :: k) conf str. Enc @k enc conf str -> str
getPayload) (Either UnexpectedDecodeEx (Enc @[Symbol] ('[] @Symbol) c str)
-> Either String str)
-> Either UnexpectedDecodeEx (Enc @[Symbol] ('[] @Symbol) c str)
-> Either String str
forall a b. (a -> b) -> a -> b
$ Decoding (Either UnexpectedDecodeEx) nm alg c str
-> Enc @[Symbol] ((':) @Symbol nm ('[] @Symbol)) c str
-> Either UnexpectedDecodeEx (Enc @[Symbol] ('[] @Symbol) c str)
forall (alg :: Symbol) (nm :: Symbol) (f :: * -> *)
(xs :: [Symbol]) conf str.
Decoding f nm alg conf str
-> Enc @[Symbol] ((':) @Symbol nm xs) conf str
-> f (Enc @[Symbol] xs conf str)
runDecoding' @alg Decoding (Either UnexpectedDecodeEx) nm alg c str
decf Enc @[Symbol] ((':) @Symbol nm ('[] @Symbol)) c str
enc
, (RecreateEx -> Either String str)
-> (Enc @[Symbol] ('[] @Symbol) c str -> Either String str)
-> Either RecreateEx (Enc @[Symbol] ('[] @Symbol) c str)
-> Either String str
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either (String -> Either String str
forall a b. a -> Either a b
Left (String -> Either String str)
-> (RecreateEx -> String) -> RecreateEx -> Either String str
forall b c a. (b -> c) -> (a -> b) -> a -> c
. RecreateEx -> String
forall a. Show a => a -> String
show) (str -> Either String str
forall a b. b -> Either a b
Right (str -> Either String str)
-> (Enc @[Symbol] ('[] @Symbol) c str -> str)
-> Enc @[Symbol] ('[] @Symbol) c str
-> Either String str
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Enc @[Symbol] ('[] @Symbol) c str -> str
forall k (enc :: k) conf str. Enc @k enc conf str -> str
getPayload) (Either RecreateEx (Enc @[Symbol] ('[] @Symbol) c str)
-> Either String str)
-> Either RecreateEx (Enc @[Symbol] ('[] @Symbol) c str)
-> Either String str
forall a b. (a -> b) -> a -> b
$ Validation (Either RecreateEx) nm alg c str
-> Enc @[Symbol] ((':) @Symbol nm ('[] @Symbol)) c str
-> Either RecreateEx (Enc @[Symbol] ('[] @Symbol) c str)
forall (alg :: Symbol) (nm :: Symbol) (f :: * -> *)
(xs :: [Symbol]) conf str.
Validation f nm alg conf str
-> Enc @[Symbol] ((':) @Symbol nm xs) conf str
-> f (Enc @[Symbol] xs conf str)
runValidation' @alg Validation (Either RecreateEx) nm alg c str
validf Enc @[Symbol] ((':) @Symbol nm ('[] @Symbol)) c str
enc)
Left RecreateEx
_ -> (String -> Either String str
forall a b. a -> Either a b
Left String
"not-recovered", String -> Either String str
forall a b. a -> Either a b
Left String
"not-recovered")
_propSafeValidatedDecoding :: forall nm c str alg. (Algorithm nm alg, Eq c, Eq str) =>
Validation (Either RecreateEx) nm alg c str
-> Decoding (Either UnexpectedDecodeEx) nm alg c str
-> c
-> str
-> Bool
_propSafeValidatedDecoding :: Validation (Either RecreateEx) nm alg c str
-> Decoding (Either UnexpectedDecodeEx) nm alg c str
-> c
-> str
-> Bool
_propSafeValidatedDecoding = forall (nm :: Symbol) c str.
(Eq c, Eq str) =>
Validation (Either RecreateEx) nm (AlgNm nm) c str
-> Decoding (Either UnexpectedDecodeEx) nm (AlgNm nm) c str
-> c
-> str
-> Bool
forall (alg :: Symbol) (nm :: Symbol) c str.
(Eq c, Eq str) =>
Validation (Either RecreateEx) nm alg c str
-> Decoding (Either UnexpectedDecodeEx) nm alg c str
-> c
-> str
-> Bool
propSafeValidatedDecoding' @(AlgNm nm)