-- |
-- Module       : Data.ByteString.Base16.Types.Internal
-- Copyright    : (c) 2019-2022 Emily Pillmore
-- License      : BSD-style
--
-- Maintainer   : Emily Pillmore <emilypi@cohomolo.gy>,
--                sofia-m-a <https://github.com/sofia-m-a>
-- Stability    : stable
-- Portability  : non-portable
--
-- This module contains the 'Base16' newtype.
--
module Data.Base16.Types.Internal
( Base16(..)
) where


import Control.DeepSeq

import Data.Functor.Classes

-- | Wraps a value, asserting that it is or is intended to be
-- in a particular kind of Base16 encoding use 'extractBase16'
-- to extract the value, and 'assertBase16' to tag a value
-- as base16-encoded
--
newtype Base16 a = Base16 a

instance Eq a => Eq (Base16 a) where
  Base16 a
a == :: Base16 a -> Base16 a -> Bool
== Base16 a
b = a
a forall a. Eq a => a -> a -> Bool
== a
b

instance Eq1 Base16 where
  liftEq :: forall a b. (a -> b -> Bool) -> Base16 a -> Base16 b -> Bool
liftEq a -> b -> Bool
f (Base16 a
a) (Base16 b
b) = a -> b -> Bool
f a
a b
b

instance Ord a => Ord (Base16 a) where
  compare :: Base16 a -> Base16 a -> Ordering
compare (Base16 a
a) (Base16 a
b) = forall a. Ord a => a -> a -> Ordering
compare a
a a
b

instance Ord1 Base16 where
  liftCompare :: forall a b.
(a -> b -> Ordering) -> Base16 a -> Base16 b -> Ordering
liftCompare a -> b -> Ordering
f (Base16 a
a) (Base16 b
b) = a -> b -> Ordering
f a
a b
b

instance Functor Base16 where
  fmap :: forall a b. (a -> b) -> Base16 a -> Base16 b
fmap a -> b
f (Base16 a
a) = forall a. a -> Base16 a
Base16 (a -> b
f a
a)

instance Applicative Base16 where
  pure :: forall a. a -> Base16 a
pure = forall a. a -> Base16 a
Base16
  Base16 a -> b
f <*> :: forall a b. Base16 (a -> b) -> Base16 a -> Base16 b
<*> Base16 a
a = forall a. a -> Base16 a
Base16 (a -> b
f a
a)

instance Monad Base16 where
  return :: forall a. a -> Base16 a
return = forall (f :: * -> *) a. Applicative f => a -> f a
pure
  Base16 a
a >>= :: forall a b. Base16 a -> (a -> Base16 b) -> Base16 b
>>= a -> Base16 b
k = a -> Base16 b
k a
a

instance Show a => Show (Base16 a) where
  show :: Base16 a -> String
show (Base16 a
a) = forall a. Show a => a -> String
show a
a

instance NFData a => NFData (Base16 a) where
  rnf :: Base16 a -> ()
rnf (Base16 a
a) = forall a. NFData a => a -> ()
rnf a
a