{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE TypeFamilies #-}
module ELynx.Data.Alphabet.Character
( Character,
toWord,
fromWord,
toChar,
fromChar,
toString,
fromString,
toCVec,
fromCVec,
)
where
import Data.ByteString.Internal (c2w, w2c)
import qualified Data.Vector.Unboxed as V
import Data.Vector.Unboxed.Deriving
import Data.Word8
import qualified ELynx.Data.Character.Character as C
newtype Character = Character Word8
deriving (Read, Show, Eq, Ord, Bounded)
toWord :: Character -> Word8
toWord (Character w) = w
fromWord :: Word8 -> Character
fromWord = Character
toChar :: Character -> Char
toChar (Character w) = w2c w
fromChar :: Char -> Character
fromChar = Character . c2w
toString :: [Character] -> String
toString = map toChar
fromString :: String -> [Character]
fromString = map fromChar
toCVec :: C.Character a => V.Vector Character -> V.Vector a
toCVec = V.map (C.fromWord . toWord)
fromCVec :: C.Character a => V.Vector a -> V.Vector Character
fromCVec = V.map (fromWord . C.toWord)
derivingUnbox
"Character"
[t|Character -> Word8|]
[|\(Character w) -> w|]
[|Character|]