module Parsers.Utils ( module Parsers.Utils , w2c ) where import Data.Char (Char) import Data.Function ((.), id) import Data.Word (Word8) import Prelude (Enum(..)) import Data.ByteString.Internal (w2c, c2w) -- * Class 'CoerceEnum' -- | Convenient helper to write generic grammars -- consuming either 'Word8' or 'Char'. class CoerceEnum a b where coerceEnum :: a -> b default coerceEnum :: Enum a => Enum b => a -> b coerceEnum = toEnum . fromEnum instance CoerceEnum Word8 Char where coerceEnum = w2c instance CoerceEnum Char Word8 where coerceEnum = c2w instance CoerceEnum Char Char where coerceEnum = id