typed-encoding-0.5.2.1: Type safe string transformations

Safe HaskellSafe
LanguageHaskell2010

Data.TypedEncoding.Common.Types.CheckedEnc

Contents

Description

Module defines CheckedEnc - untyped ADT version of Enc

A more dependently typed approach would be to define SomeEnc GADT that accepts some Enc '[..] in its constructor. The approach here turns out to be isomorphic to SomeEnc approach. Both, however, yield somewhat different programming.

Post v0.4 typed-encoding does not support SomeEnc and it remains only as an Example.

See Examples.TypedEncoding.SomeEnc.

This module is re-exported in Data.TypedEncoding and it is best not to import it directly.

Synopsis

Documentation

>>> :set -XOverloadedStrings -XMultiParamTypeClasses -XDataKinds -XAllowAmbiguousTypes
>>> import qualified Data.Text as T
>>> import  Data.TypedEncoding.Combinators.Unsafe (unsafeSetPayload)

Untyped Enc

data CheckedEnc conf str Source #

Represents some validated encoded string.

CheckedEnc is untyped version of Enc. CheckedEnc contains verified encoded data, encoding is visible at the value level only.

Since: 0.2.0.0

Constructors

UnsafeMkCheckedEnc [EncAnn] conf str

Constructor renamed from previous versions This constructor is considered unsafe as pattern matching on it and using it allows access to the encoded payload.

Since: 0.3.0.0

Instances
(Eq conf, Eq str) => Eq (CheckedEnc conf str) Source # 
Instance details

Defined in Data.TypedEncoding.Common.Types.CheckedEnc

Methods

(==) :: CheckedEnc conf str -> CheckedEnc conf str -> Bool #

(/=) :: CheckedEnc conf str -> CheckedEnc conf str -> Bool #

(Show conf, Show str) => Show (CheckedEnc conf str) Source # 
Instance details

Defined in Data.TypedEncoding.Common.Types.CheckedEnc

Methods

showsPrec :: Int -> CheckedEnc conf str -> ShowS #

show :: CheckedEnc conf str -> String #

showList :: [CheckedEnc conf str] -> ShowS #

(Show c, Displ str) => Displ (CheckedEnc c str) Source #
>>> displ $ unsafeCheckedEnc ["TEST"] () ("hello" :: T.Text)
"UnsafeMkCheckedEnc [TEST] () (Text hello)"
Instance details

Defined in Data.TypedEncoding.Common.Types.CheckedEnc

Methods

displ :: CheckedEnc c str -> String Source #

unsafeCheckedEnc :: [EncAnn] -> c -> s -> CheckedEnc c s Source #

Since: 0.2.0.0

getCheckedPayload :: CheckedEnc conf str -> str Source #

Since: 0.2.0.0

getCheckedEncPayload :: CheckedEnc conf str -> ([EncAnn], str) Source #

Since: 0.2.0.0

toCheckedEnc :: forall xs c str. SymbolList xs => Enc xs c str -> CheckedEnc c str Source #

Since: 0.2.0.0

fromCheckedEnc :: forall xs c str. SymbolList xs => CheckedEnc c str -> Maybe (Enc xs c str) Source #

Since: 0.2.0.0

procToCheckedEncFromCheckedEnc :: forall xs c str. (SymbolList xs, Eq c, Eq str) => CheckedEnc c str -> Bool Source #

>>> let encsometest = UnsafeMkCheckedEnc ["TEST"] () $ T.pack "hello"
>>> procToCheckedEncFromCheckedEnc @'["TEST"] encsometest
True
>>> procToCheckedEncFromCheckedEnc @'["TEST1"] encsometest
False

procFromCheckedEncToCheckedEnc :: forall xs c str. (SymbolList xs, Eq c, Eq str) => Enc xs c str -> Bool Source #

>>> let enctest = unsafeSetPayload () "hello" :: Enc '["TEST"] () T.Text
>>> procFromCheckedEncToCheckedEnc enctest
True