    -- This Source Code Form is subject to the terms of the Mozilla Public
    -- License, v. 2.0. If a copy of the MPL was not distributed with this
    -- file, You can obtain one at http://mozilla.org/MPL/2.0/.

    {-# LANGUAGE GeneralizedNewtypeDeriving #-}

    module Data.ByteString.Conversion.Internal where

    import Control.Applicative
    import Data.Bits (Bits)
    import Text.Printf (PrintfArg)
    import Prelude

    -- | Newtype wrapper to parse and produce integral numbers in
    -- hexadecimal format
    newtype Hex a = Hex { forall a. Hex a -> a
    fromHex :: a }
        deriving ( Hex a -> Hex a -> Bool
    (Hex a -> Hex a -> Bool) -> (Hex a -> Hex a -> Bool) -> Eq (Hex a)
    forall a. Eq a => Hex a -> Hex a -> Bool
    forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
    $c== :: forall a. Eq a => Hex a -> Hex a -> Bool
    == :: Hex a -> Hex a -> Bool
    $c/= :: forall a. Eq a => Hex a -> Hex a -> Bool
    /= :: Hex a -> Hex a -> Bool
    Eq
                 , Eq (Hex a)
    Eq (Hex a) =>
    (Hex a -> Hex a -> Ordering)
    -> (Hex a -> Hex a -> Bool)
    -> (Hex a -> Hex a -> Bool)
    -> (Hex a -> Hex a -> Bool)
    -> (Hex a -> Hex a -> Bool)
    -> (Hex a -> Hex a -> Hex a)
    -> (Hex a -> Hex a -> Hex a)
    -> Ord (Hex a)
    Hex a -> Hex a -> Bool
    Hex a -> Hex a -> Ordering
    Hex a -> Hex a -> Hex a
    forall a.
    Eq a =>
    (a -> a -> Ordering)
    -> (a -> a -> Bool)
    -> (a -> a -> Bool)
    -> (a -> a -> Bool)
    -> (a -> a -> Bool)
    -> (a -> a -> a)
    -> (a -> a -> a)
    -> Ord a
    forall a. Ord a => Eq (Hex a)
    forall a. Ord a => Hex a -> Hex a -> Bool
    forall a. Ord a => Hex a -> Hex a -> Ordering
    forall a. Ord a => Hex a -> Hex a -> Hex a
    $ccompare :: forall a. Ord a => Hex a -> Hex a -> Ordering
    compare :: Hex a -> Hex a -> Ordering
    $c< :: forall a. Ord a => Hex a -> Hex a -> Bool
    < :: Hex a -> Hex a -> Bool
    $c<= :: forall a. Ord a => Hex a -> Hex a -> Bool
    <= :: Hex a -> Hex a -> Bool
    $c> :: forall a. Ord a => Hex a -> Hex a -> Bool
    > :: Hex a -> Hex a -> Bool
    $c>= :: forall a. Ord a => Hex a -> Hex a -> Bool
    >= :: Hex a -> Hex a -> Bool
    $cmax :: forall a. Ord a => Hex a -> Hex a -> Hex a
    max :: Hex a -> Hex a -> Hex a
    $cmin :: forall a. Ord a => Hex a -> Hex a -> Hex a
    min :: Hex a -> Hex a -> Hex a
    Ord
                 , Integer -> Hex a
    Hex a -> Hex a
    Hex a -> Hex a -> Hex a
    (Hex a -> Hex a -> Hex a)
    -> (Hex a -> Hex a -> Hex a)
    -> (Hex a -> Hex a -> Hex a)
    -> (Hex a -> Hex a)
    -> (Hex a -> Hex a)
    -> (Hex a -> Hex a)
    -> (Integer -> Hex a)
    -> Num (Hex a)
    forall a. Num a => Integer -> Hex a
    forall a. Num a => Hex a -> Hex a
    forall a. Num a => Hex a -> Hex a -> Hex a
    forall a.
    (a -> a -> a)
    -> (a -> a -> a)
    -> (a -> a -> a)
    -> (a -> a)
    -> (a -> a)
    -> (a -> a)
    -> (Integer -> a)
    -> Num a
    $c+ :: forall a. Num a => Hex a -> Hex a -> Hex a
    + :: Hex a -> Hex a -> Hex a
    $c- :: forall a. Num a => Hex a -> Hex a -> Hex a
    - :: Hex a -> Hex a -> Hex a
    $c* :: forall a. Num a => Hex a -> Hex a -> Hex a
    * :: Hex a -> Hex a -> Hex a
    $cnegate :: forall a. Num a => Hex a -> Hex a
    negate :: Hex a -> Hex a
    $cabs :: forall a. Num a => Hex a -> Hex a
    abs :: Hex a -> Hex a
    $csignum :: forall a. Num a => Hex a -> Hex a
    signum :: Hex a -> Hex a
    $cfromInteger :: forall a. Num a => Integer -> Hex a
    fromInteger :: Integer -> Hex a
    Num
                 , ReadPrec [Hex a]
    ReadPrec (Hex a)
    Int -> ReadS (Hex a)
    ReadS [Hex a]
    (Int -> ReadS (Hex a))
    -> ReadS [Hex a]
    -> ReadPrec (Hex a)
    -> ReadPrec [Hex a]
    -> Read (Hex a)
    forall a. Read a => ReadPrec [Hex a]
    forall a. Read a => ReadPrec (Hex a)
    forall a. Read a => Int -> ReadS (Hex a)
    forall a. Read a => ReadS [Hex a]
    forall a.
    (Int -> ReadS a)
    -> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
    $creadsPrec :: forall a. Read a => Int -> ReadS (Hex a)
    readsPrec :: Int -> ReadS (Hex a)
    $creadList :: forall a. Read a => ReadS [Hex a]
    readList :: ReadS [Hex a]
    $creadPrec :: forall a. Read a => ReadPrec (Hex a)
    readPrec :: ReadPrec (Hex a)
    $creadListPrec :: forall a. Read a => ReadPrec [Hex a]
    readListPrec :: ReadPrec [Hex a]
    Read
                 , Int -> Hex a -> ShowS
    [Hex a] -> ShowS
    Hex a -> String
    (Int -> Hex a -> ShowS)
    -> (Hex a -> String) -> ([Hex a] -> ShowS) -> Show (Hex a)
    forall a. Show a => Int -> Hex a -> ShowS
    forall a. Show a => [Hex a] -> ShowS
    forall a. Show a => Hex a -> String
    forall a.
    (Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
    $cshowsPrec :: forall a. Show a => Int -> Hex a -> ShowS
    showsPrec :: Int -> Hex a -> ShowS
    $cshow :: forall a. Show a => Hex a -> String
    show :: Hex a -> String
    $cshowList :: forall a. Show a => [Hex a] -> ShowS
    showList :: [Hex a] -> ShowS
    Show
                 , Hex a
    Hex a -> Hex a -> Bounded (Hex a)
    forall a. a -> a -> Bounded a
    forall a. Bounded a => Hex a
    $cminBound :: forall a. Bounded a => Hex a
    minBound :: Hex a
    $cmaxBound :: forall a. Bounded a => Hex a
    maxBound :: Hex a
    Bounded
                 , Enum (Hex a)
    Real (Hex a)
    (Real (Hex a), Enum (Hex a)) =>
    (Hex a -> Hex a -> Hex a)
    -> (Hex a -> Hex a -> Hex a)
    -> (Hex a -> Hex a -> Hex a)
    -> (Hex a -> Hex a -> Hex a)
    -> (Hex a -> Hex a -> (Hex a, Hex a))
    -> (Hex a -> Hex a -> (Hex a, Hex a))
    -> (Hex a -> Integer)
    -> Integral (Hex a)
    Hex a -> Integer
    Hex a -> Hex a -> (Hex a, Hex a)
    Hex a -> Hex a -> Hex a
    forall a. Integral a => Enum (Hex a)
    forall a. Integral a => Real (Hex a)
    forall a. Integral a => Hex a -> Integer
    forall a. Integral a => Hex a -> Hex a -> (Hex a, Hex a)
    forall a. Integral a => Hex a -> Hex a -> Hex a
    forall a.
    (Real a, Enum a) =>
    (a -> a -> a)
    -> (a -> a -> a)
    -> (a -> a -> a)
    -> (a -> a -> a)
    -> (a -> a -> (a, a))
    -> (a -> a -> (a, a))
    -> (a -> Integer)
    -> Integral a
    $cquot :: forall a. Integral a => Hex a -> Hex a -> Hex a
    quot :: Hex a -> Hex a -> Hex a
    $crem :: forall a. Integral a => Hex a -> Hex a -> Hex a
    rem :: Hex a -> Hex a -> Hex a
    $cdiv :: forall a. Integral a => Hex a -> Hex a -> Hex a
    div :: Hex a -> Hex a -> Hex a
    $cmod :: forall a. Integral a => Hex a -> Hex a -> Hex a
    mod :: Hex a -> Hex a -> Hex a
    $cquotRem :: forall a. Integral a => Hex a -> Hex a -> (Hex a, Hex a)
    quotRem :: Hex a -> Hex a -> (Hex a, Hex a)
    $cdivMod :: forall a. Integral a => Hex a -> Hex a -> (Hex a, Hex a)
    divMod :: Hex a -> Hex a -> (Hex a, Hex a)
    $ctoInteger :: forall a. Integral a => Hex a -> Integer
    toInteger :: Hex a -> Integer
    Integral
                 , Eq (Hex a)
    Hex a
    Eq (Hex a) =>
    (Hex a -> Hex a -> Hex a)
    -> (Hex a -> Hex a -> Hex a)
    -> (Hex a -> Hex a -> Hex a)
    -> (Hex a -> Hex a)
    -> (Hex a -> Int -> Hex a)
    -> (Hex a -> Int -> Hex a)
    -> Hex a
    -> (Int -> Hex a)
    -> (Hex a -> Int -> Hex a)
    -> (Hex a -> Int -> Hex a)
    -> (Hex a -> Int -> Hex a)
    -> (Hex a -> Int -> Bool)
    -> (Hex a -> Maybe Int)
    -> (Hex a -> Int)
    -> (Hex a -> Bool)
    -> (Hex a -> Int -> Hex a)
    -> (Hex a -> Int -> Hex a)
    -> (Hex a -> Int -> Hex a)
    -> (Hex a -> Int -> Hex a)
    -> (Hex a -> Int -> Hex a)
    -> (Hex a -> Int -> Hex a)
    -> (Hex a -> Int)
    -> Bits (Hex a)
    Int -> Hex a
    Hex a -> Bool
    Hex a -> Int
    Hex a -> Maybe Int
    Hex a -> Hex a
    Hex a -> Int -> Bool
    Hex a -> Int -> Hex a
    Hex a -> Hex a -> Hex a
    forall a.
    Eq a =>
    (a -> a -> a)
    -> (a -> a -> a)
    -> (a -> a -> a)
    -> (a -> a)
    -> (a -> Int -> a)
    -> (a -> Int -> a)
    -> a
    -> (Int -> a)
    -> (a -> Int -> a)
    -> (a -> Int -> a)
    -> (a -> Int -> a)
    -> (a -> Int -> Bool)
    -> (a -> Maybe Int)
    -> (a -> Int)
    -> (a -> Bool)
    -> (a -> Int -> a)
    -> (a -> Int -> a)
    -> (a -> Int -> a)
    -> (a -> Int -> a)
    -> (a -> Int -> a)
    -> (a -> Int -> a)
    -> (a -> Int)
    -> Bits a
    forall a. Bits a => Eq (Hex a)
    forall a. Bits a => Hex a
    forall a. Bits a => Int -> Hex a
    forall a. Bits a => Hex a -> Bool
    forall a. Bits a => Hex a -> Int
    forall a. Bits a => Hex a -> Maybe Int
    forall a. Bits a => Hex a -> Hex a
    forall a. Bits a => Hex a -> Int -> Bool
    forall a. Bits a => Hex a -> Int -> Hex a
    forall a. Bits a => Hex a -> Hex a -> Hex a
    $c.&. :: forall a. Bits a => Hex a -> Hex a -> Hex a
    .&. :: Hex a -> Hex a -> Hex a
    $c.|. :: forall a. Bits a => Hex a -> Hex a -> Hex a
    .|. :: Hex a -> Hex a -> Hex a
    $cxor :: forall a. Bits a => Hex a -> Hex a -> Hex a
    xor :: Hex a -> Hex a -> Hex a
    $ccomplement :: forall a. Bits a => Hex a -> Hex a
    complement :: Hex a -> Hex a
    $cshift :: forall a. Bits a => Hex a -> Int -> Hex a
    shift :: Hex a -> Int -> Hex a
    $crotate :: forall a. Bits a => Hex a -> Int -> Hex a
    rotate :: Hex a -> Int -> Hex a
    $czeroBits :: forall a. Bits a => Hex a
    zeroBits :: Hex a
    $cbit :: forall a. Bits a => Int -> Hex a
    bit :: Int -> Hex a
    $csetBit :: forall a. Bits a => Hex a -> Int -> Hex a
    setBit :: Hex a -> Int -> Hex a
    $cclearBit :: forall a. Bits a => Hex a -> Int -> Hex a
    clearBit :: Hex a -> Int -> Hex a
    $ccomplementBit :: forall a. Bits a => Hex a -> Int -> Hex a
    complementBit :: Hex a -> Int -> Hex a
    $ctestBit :: forall a. Bits a => Hex a -> Int -> Bool
    testBit :: Hex a -> Int -> Bool
    $cbitSizeMaybe :: forall a. Bits a => Hex a -> Maybe Int
    bitSizeMaybe :: Hex a -> Maybe Int
    $cbitSize :: forall a. Bits a => Hex a -> Int
    bitSize :: Hex a -> Int
    $cisSigned :: forall a. Bits a => Hex a -> Bool
    isSigned :: Hex a -> Bool
    $cshiftL :: forall a. Bits a => Hex a -> Int -> Hex a
    shiftL :: Hex a -> Int -> Hex a
    $cunsafeShiftL :: forall a. Bits a => Hex a -> Int -> Hex a
    unsafeShiftL :: Hex a -> Int -> Hex a
    $cshiftR :: forall a. Bits a => Hex a -> Int -> Hex a
    shiftR :: Hex a -> Int -> Hex a
    $cunsafeShiftR :: forall a. Bits a => Hex a -> Int -> Hex a
    unsafeShiftR :: Hex a -> Int -> Hex a
    $crotateL :: forall a. Bits a => Hex a -> Int -> Hex a
    rotateL :: Hex a -> Int -> Hex a
    $crotateR :: forall a. Bits a => Hex a -> Int -> Hex a
    rotateR :: Hex a -> Int -> Hex a
    $cpopCount :: forall a. Bits a => Hex a -> Int
    popCount :: Hex a -> Int
    Bits
                 , Hex a -> ModifierParser
    Hex a -> FieldFormatter
    (Hex a -> FieldFormatter)
    -> (Hex a -> ModifierParser) -> PrintfArg (Hex a)
    forall a. PrintfArg a => Hex a -> ModifierParser
    forall a. PrintfArg a => Hex a -> FieldFormatter
    forall a.
    (a -> FieldFormatter) -> (a -> ModifierParser) -> PrintfArg a
    $cformatArg :: forall a. PrintfArg a => Hex a -> FieldFormatter
    formatArg :: Hex a -> FieldFormatter
    $cparseFormat :: forall a. PrintfArg a => Hex a -> ModifierParser
    parseFormat :: Hex a -> ModifierParser
    PrintfArg
                 , Int -> Hex a
    Hex a -> Int
    Hex a -> [Hex a]
    Hex a -> Hex a
    Hex a -> Hex a -> [Hex a]
    Hex a -> Hex a -> Hex a -> [Hex a]
    (Hex a -> Hex a)
    -> (Hex a -> Hex a)
    -> (Int -> Hex a)
    -> (Hex a -> Int)
    -> (Hex a -> [Hex a])
    -> (Hex a -> Hex a -> [Hex a])
    -> (Hex a -> Hex a -> [Hex a])
    -> (Hex a -> Hex a -> Hex a -> [Hex a])
    -> Enum (Hex a)
    forall a. Enum a => Int -> Hex a
    forall a. Enum a => Hex a -> Int
    forall a. Enum a => Hex a -> [Hex a]
    forall a. Enum a => Hex a -> Hex a
    forall a. Enum a => Hex a -> Hex a -> [Hex a]
    forall a. Enum a => Hex a -> Hex a -> Hex a -> [Hex a]
    forall a.
    (a -> a)
    -> (a -> a)
    -> (Int -> a)
    -> (a -> Int)
    -> (a -> [a])
    -> (a -> a -> [a])
    -> (a -> a -> [a])
    -> (a -> a -> a -> [a])
    -> Enum a
    $csucc :: forall a. Enum a => Hex a -> Hex a
    succ :: Hex a -> Hex a
    $cpred :: forall a. Enum a => Hex a -> Hex a
    pred :: Hex a -> Hex a
    $ctoEnum :: forall a. Enum a => Int -> Hex a
    toEnum :: Int -> Hex a
    $cfromEnum :: forall a. Enum a => Hex a -> Int
    fromEnum :: Hex a -> Int
    $cenumFrom :: forall a. Enum a => Hex a -> [Hex a]
    enumFrom :: Hex a -> [Hex a]
    $cenumFromThen :: forall a. Enum a => Hex a -> Hex a -> [Hex a]
    enumFromThen :: Hex a -> Hex a -> [Hex a]
    $cenumFromTo :: forall a. Enum a => Hex a -> Hex a -> [Hex a]
    enumFromTo :: Hex a -> Hex a -> [Hex a]
    $cenumFromThenTo :: forall a. Enum a => Hex a -> Hex a -> Hex a -> [Hex a]
    enumFromThenTo :: Hex a -> Hex a -> Hex a -> [Hex a]
    Enum
                 , Num (Hex a)
    Ord (Hex a)
    (Num (Hex a), Ord (Hex a)) => (Hex a -> Rational) -> Real (Hex a)
    Hex a -> Rational
    forall a. (Num a, Ord a) => (a -> Rational) -> Real a
    forall a. Real a => Num (Hex a)
    forall a. Real a => Ord (Hex a)
    forall a. Real a => Hex a -> Rational
    $ctoRational :: forall a. Real a => Hex a -> Rational
    toRational :: Hex a -> Rational
    Real
                 )

    -- | Newtype wrapper to parse and produce a comma separated list
    -- of values.
    newtype List a = List { forall a. List a -> [a]
    fromList :: [a] }
        deriving ( List a -> List a -> Bool
    (List a -> List a -> Bool)
    -> (List a -> List a -> Bool) -> Eq (List a)
    forall a. Eq a => List a -> List a -> Bool
    forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
    $c== :: forall a. Eq a => List a -> List a -> Bool
    == :: List a -> List a -> Bool
    $c/= :: forall a. Eq a => List a -> List a -> Bool
    /= :: List a -> List a -> Bool
    Eq
                 , Int -> List a -> ShowS
    [List a] -> ShowS
    List a -> String
    (Int -> List a -> ShowS)
    -> (List a -> String) -> ([List a] -> ShowS) -> Show (List a)
    forall a. Show a => Int -> List a -> ShowS
    forall a. Show a => [List a] -> ShowS
    forall a. Show a => List a -> String
    forall a.
    (Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
    $cshowsPrec :: forall a. Show a => Int -> List a -> ShowS
    showsPrec :: Int -> List a -> ShowS
    $cshow :: forall a. Show a => List a -> String
    show :: List a -> String
    $cshowList :: forall a. Show a => [List a] -> ShowS
    showList :: [List a] -> ShowS
    Show
                 , (forall a b. (a -> b) -> List a -> List b)
    -> (forall a b. a -> List b -> List a) -> Functor List
    forall a b. a -> List b -> List a
    forall a b. (a -> b) -> List a -> List b
    forall (f :: * -> *).
    (forall a b. (a -> b) -> f a -> f b)
    -> (forall a b. a -> f b -> f a) -> Functor f
    $cfmap :: forall a b. (a -> b) -> List a -> List b
    fmap :: forall a b. (a -> b) -> List a -> List b
    $c<$ :: forall a b. a -> List b -> List a
    <$ :: forall a b. a -> List b -> List a
    Functor
                 , Functor List
    Functor List =>
    (forall a. a -> List a)
    -> (forall a b. List (a -> b) -> List a -> List b)
    -> (forall a b c. (a -> b -> c) -> List a -> List b -> List c)
    -> (forall a b. List a -> List b -> List b)
    -> (forall a b. List a -> List b -> List a)
    -> Applicative List
    forall a. a -> List a
    forall a b. List a -> List b -> List a
    forall a b. List a -> List b -> List b
    forall a b. List (a -> b) -> List a -> List b
    forall a b c. (a -> b -> c) -> List a -> List b -> List c
    forall (f :: * -> *).
    Functor f =>
    (forall a. a -> f a)
    -> (forall a b. f (a -> b) -> f a -> f b)
    -> (forall a b c. (a -> b -> c) -> f a -> f b -> f c)
    -> (forall a b. f a -> f b -> f b)
    -> (forall a b. f a -> f b -> f a)
    -> Applicative f
    $cpure :: forall a. a -> List a
    pure :: forall a. a -> List a
    $c<*> :: forall a b. List (a -> b) -> List a -> List b
    <*> :: forall a b. List (a -> b) -> List a -> List b
    $cliftA2 :: forall a b c. (a -> b -> c) -> List a -> List b -> List c
    liftA2 :: forall a b c. (a -> b -> c) -> List a -> List b -> List c
    $c*> :: forall a b. List a -> List b -> List b
    *> :: forall a b. List a -> List b -> List b
    $c<* :: forall a b. List a -> List b -> List a
    <* :: forall a b. List a -> List b -> List a
    Applicative
                 , Applicative List
    Applicative List =>
    (forall a b. List a -> (a -> List b) -> List b)
    -> (forall a b. List a -> List b -> List b)
    -> (forall a. a -> List a)
    -> Monad List
    forall a. a -> List a
    forall a b. List a -> List b -> List b
    forall a b. List a -> (a -> List b) -> List b
    forall (m :: * -> *).
    Applicative m =>
    (forall a b. m a -> (a -> m b) -> m b)
    -> (forall a b. m a -> m b -> m b)
    -> (forall a. a -> m a)
    -> Monad m
    $c>>= :: forall a b. List a -> (a -> List b) -> List b
    >>= :: forall a b. List a -> (a -> List b) -> List b
    $c>> :: forall a b. List a -> List b -> List b
    >> :: forall a b. List a -> List b -> List b
    $creturn :: forall a. a -> List a
    return :: forall a. a -> List a
    Monad
                 )