{-# LANGUAGE GADTs #-}
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE AllowAmbiguousTypes #-}
module Data.TypedEncoding.Internal.Types (
module Data.TypedEncoding.Internal.Types
, module Data.TypedEncoding.Internal.Types.Enc
, module Data.TypedEncoding.Internal.Types.CheckedEnc
, module Data.TypedEncoding.Internal.Types.UncheckedEnc
, module Data.TypedEncoding.Internal.Types.Common
) where
import Data.TypedEncoding.Internal.Types.Enc
import Data.TypedEncoding.Internal.Types.CheckedEnc
import Data.TypedEncoding.Internal.Types.UncheckedEnc
import Data.TypedEncoding.Internal.Types.Common
import Data.Proxy
import GHC.TypeLits
data RecreateEx where
RecreateEx:: (Show e, KnownSymbol x) => Proxy x -> e -> RecreateEx
RecreateExUnkStep:: (Show e) => e -> RecreateEx
instance Show RecreateEx where
show (RecreateEx prxy a) = "(RecreateEx \"" ++ symbolVal prxy ++ "\" (" ++ show a ++ "))"
show (RecreateExUnkStep a) = "(UnknownDecodeStep (" ++ show a ++ "))"
recreateErrUnknown :: (Show e) => e -> RecreateEx
recreateErrUnknown = RecreateExUnkStep
data EncodeEx where
EncodeEx:: (Show a, KnownSymbol x) => Proxy x -> a -> EncodeEx
instance Show EncodeEx where
show (EncodeEx prxy a) = "(EncodeEx \"" ++ symbolVal prxy ++ "\" (" ++ show a ++ "))"
data UnexpectedDecodeEx where
UnexpectedDecodeEx :: (Show a, KnownSymbol x) => Proxy x -> a -> UnexpectedDecodeEx
instance Show UnexpectedDecodeEx where
show (UnexpectedDecodeEx prxy a) = "(UnexpectedDecodeEx \"" ++ symbolVal prxy ++ "\" (" ++ show a ++ "))"
implEncodeF_ :: (Show err, KnownSymbol x) => Proxy x -> (str -> Either err str) -> Enc enc1 conf str -> Either EncodeEx (Enc enc2 conf str)
implEncodeF_ p f = implTranF (either (Left . EncodeEx p) Right . f)
implEncodeF :: forall x enc1 enc2 err conf str .
(Show err, KnownSymbol x)
=> (str -> Either err str) -> Enc enc1 conf str -> Either EncodeEx (Enc enc2 conf str)
implEncodeF = implEncodeF_ (Proxy :: Proxy x)
implEncodeF_' :: (Show err, KnownSymbol x) => Proxy x -> (conf -> str -> Either err str) -> Enc enc1 conf str -> Either EncodeEx (Enc enc2 conf str)
implEncodeF_' p f = implTranF' (\c -> either (Left . EncodeEx p) Right . f c)