{-# LANGUAGE DataKinds #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE UndecidableInstances #-}
module Data.TypedEncoding.Combinators.Restriction.Common where
import GHC.TypeLits
import Data.TypedEncoding.Internal.Util.TypeLits
import Data.TypedEncoding.Instances.Support
decFR :: (IsR s ~ 'True, Applicative f) =>
Enc (s ': xs) c str -> f (Enc xs c str)
decFR = implTranP id
recWithEncR :: forall (s :: Symbol) xs c str . (IsR s ~ 'True)
=> (Enc xs c str -> Either EncodeEx (Enc (s ': xs) c str))
-> Enc xs c str -> Either RecreateEx (Enc (s ': xs) c str)
recWithEncR = unsafeRecWithEncR
unsafeRecWithEncR :: forall (s :: Symbol) xs c str .
(Enc xs c str -> Either EncodeEx (Enc (s ': xs) c str))
-> Enc xs c str -> Either RecreateEx (Enc (s ': xs) c str)
unsafeRecWithEncR fn = either (Left . encToRecrEx) Right . fn
type family IsR (s :: Symbol) :: Bool where
IsR s = AcceptEq ('Text "Not restriction encoding " ':<>: ShowType s ) (CmpSymbol "r-" (Take 2 s))
type family IsROrEmpty (s :: Symbol) :: Bool where
IsROrEmpty "" = True
IsROrEmpty x = IsR x