{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE TemplateHaskell #-}

module Data.Digit.Binary(
  BinDigit(..)
, BinaryNoZero
, Binary
, parseBinaryNoZero
, parseBinary
-- * Prisms
, _BinDigit0
, _BinDigit1
-- * Re-exports
, module Data.Digit.Class.D0
, module Data.Digit.Class.D1
) where

import Prelude (Eq, Show, Ord)
import Control.Lens.TH (makePrisms)
import Text.Parser.Char(CharParsing)
import Text.Parser.Combinators((<?>), choice)

import Data.Digit.Class.D0
import Data.Digit.Class.D1

data BinDigit
  = BinDigit0
  | BinDigit1
  deriving (Int -> BinDigit -> ShowS
[BinDigit] -> ShowS
BinDigit -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [BinDigit] -> ShowS
$cshowList :: [BinDigit] -> ShowS
show :: BinDigit -> String
$cshow :: BinDigit -> String
showsPrec :: Int -> BinDigit -> ShowS
$cshowsPrec :: Int -> BinDigit -> ShowS
Show, BinDigit -> BinDigit -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: BinDigit -> BinDigit -> Bool
$c/= :: BinDigit -> BinDigit -> Bool
== :: BinDigit -> BinDigit -> Bool
$c== :: BinDigit -> BinDigit -> Bool
Eq, Eq BinDigit
BinDigit -> BinDigit -> Bool
BinDigit -> BinDigit -> Ordering
BinDigit -> BinDigit -> BinDigit
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
min :: BinDigit -> BinDigit -> BinDigit
$cmin :: BinDigit -> BinDigit -> BinDigit
max :: BinDigit -> BinDigit -> BinDigit
$cmax :: BinDigit -> BinDigit -> BinDigit
>= :: BinDigit -> BinDigit -> Bool
$c>= :: BinDigit -> BinDigit -> Bool
> :: BinDigit -> BinDigit -> Bool
$c> :: BinDigit -> BinDigit -> Bool
<= :: BinDigit -> BinDigit -> Bool
$c<= :: BinDigit -> BinDigit -> Bool
< :: BinDigit -> BinDigit -> Bool
$c< :: BinDigit -> BinDigit -> Bool
compare :: BinDigit -> BinDigit -> Ordering
$ccompare :: BinDigit -> BinDigit -> Ordering
Ord)

makePrisms ''BinDigit

instance D0 BinDigit where; d0 :: Prism' BinDigit ()
d0 = Prism' BinDigit ()
_BinDigit0
instance D1 BinDigit where; d1 :: Prism' BinDigit ()
d1 = Prism' BinDigit ()
_BinDigit1

type BinaryNoZero d =
  D1 d

parseBinaryNoZero ::
  (BinaryNoZero d, CharParsing p) =>
  p d
parseBinaryNoZero :: forall d (p :: * -> *). (BinaryNoZero d, CharParsing p) => p d
parseBinaryNoZero =
  forall d (p :: * -> *). (BinaryNoZero d, CharParsing p) => p d
parse1 forall (m :: * -> *) a. Parsing m => m a -> String -> m a
<?> String
"BinaryNoZero"

type Binary d =
  (D0 d, BinaryNoZero d)

parseBinary ::
  (Binary d, CharParsing p) =>
  p d
parseBinary :: forall d (p :: * -> *). (Binary d, CharParsing p) => p d
parseBinary =
  forall (m :: * -> *) a. Alternative m => [m a] -> m a
choice
    [
      forall d (p :: * -> *). (D0 d, CharParsing p) => p d
parse0
    , forall d (p :: * -> *). (BinaryNoZero d, CharParsing p) => p d
parseBinaryNoZero
    ] forall (m :: * -> *) a. Parsing m => m a -> String -> m a
<?> String
"Binary"