{-# LANGUAGE GADTs #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE AllowAmbiguousTypes #-}
{-# LANGUAGE RankNTypes #-}
module Data.TypedEncoding.Internal.Types.SomeEnc where
import Data.TypedEncoding.Internal.Types.Enc
import Data.TypedEncoding.Internal.Class.Util
import Data.TypedEncoding.Internal.Types.SomeAnnotation
import Data.TypedEncoding.Internal.Types.CheckedEnc
data SomeEnc conf str where
MkSomeEnc :: SymbolList xs => Enc xs conf str -> SomeEnc conf str
withSomeEnc :: SomeEnc conf str -> (forall xs . SymbolList xs => Enc xs conf str -> r) -> r
withSomeEnc (MkSomeEnc enc) f = f enc
toSome :: SymbolList xs => Enc xs conf str -> SomeEnc conf str
toSome = MkSomeEnc
someToChecked :: SomeEnc conf str -> CheckedEnc conf str
someToChecked se = withSomeEnc se toCheckedEnc
checkedToSome :: CheckedEnc conf str -> SomeEnc conf str
checkedToSome (MkCheckedEnc xs c s) = withSomeAnnotation (someAnnValue xs) (\p -> MkSomeEnc (MkEnc p c s))
instance (Show c, Displ str) => Displ (SomeEnc c str) where
displ (MkSomeEnc en) =
"Some (" ++ displ en ++ ")"