binrep-0.3.1: Encode precise binary representations directly in types
Safe HaskellSafe-Inferred
LanguageHaskell2010

Binrep.Type.Magic.UTF8

Description

Inefficient attempt at UTF-8 magics.

To encode UTF-8 strings to bytestrings at compile time, we really need more support from the compiler. We can go Char -> Natural, but we can't go Natural -> [Natural] where each value is <= 255. Doing so is hard without bit twiddling.

The best we can do is get reify the Symbol directly, then encode as UTF-8 at runtime. It's a bit of a farce, and we can't derive a CBLen instance, but works just fine. Actually, I dunno, it might be faster than the bytewise magic handling, depending on how GHC optimizes its instances.

Documentation

data MagicUTF8 (str :: Symbol) Source #

Constructors

MagicUTF8 

Instances

Instances details
Show (MagicUTF8 str) Source # 
Instance details

Defined in Binrep.Type.Magic.UTF8

Methods

showsPrec :: Int -> MagicUTF8 str -> ShowS #

show :: MagicUTF8 str -> String #

showList :: [MagicUTF8 str] -> ShowS #

KnownSymbol str => BLen (MagicUTF8 str) Source # 
Instance details

Defined in Binrep.Type.Magic.UTF8

Associated Types

type CBLen (MagicUTF8 str) :: Natural Source #

Methods

blen :: MagicUTF8 str -> BLenT Source #

KnownSymbol str => Get (MagicUTF8 str) Source # 
Instance details

Defined in Binrep.Type.Magic.UTF8

Methods

get :: Getter (MagicUTF8 str) Source #

KnownSymbol str => Put (MagicUTF8 str) Source # 
Instance details

Defined in Binrep.Type.Magic.UTF8

Methods

put :: MagicUTF8 str -> Builder Source #

type CBLen (MagicUTF8 str) Source # 
Instance details

Defined in Binrep.Type.Magic.UTF8

type CBLen (MagicUTF8 str) = TypeError ('Text "No CBLen associated family instance defined for " :<>: 'ShowType (MagicUTF8 str)) :: Natural

symVal :: forall str. KnownSymbol str => String Source #