{-# LANGUAGE NoImplicitPrelude #-}

module Data.Digit.Class.D4(
  D4(..)
, parse4
) where

import Control.Category (id)
import Control.Lens (Prism', (#))

import Data.Functor ((<$))

import Text.Parser.Char(CharParsing, char)
import Text.Parser.Combinators((<?>))

-- $setup
-- >>> import Data.Digit.Class
-- >>> import Text.Parsec(parse, ParseError, eof)
-- >>> import Data.Void(Void)

class D4 d where
  d4 ::
    Prism'
      d
      ()
  x4 ::
    d
  x4 =
    Tagged () (Identity ()) -> Tagged d (Identity d)
forall d. D4 d => Prism' d ()
d4 (Tagged () (Identity ()) -> Tagged d (Identity d)) -> () -> d
forall t b. AReview t b -> b -> t
# ()

instance D4 () where
  d4 :: p () (f ()) -> p () (f ())
d4 =
    p () (f ()) -> p () (f ())
forall k (cat :: k -> k -> *) (a :: k). Category cat => cat a a
id
   
-- |
--
-- >>> parse (parse4 <* eof) "test" "4" :: Either ParseError DecDigit
-- Right DecDigit4
--
-- >>> parse parse4 "test" "4xyz" :: Either ParseError DecDigit
-- Right DecDigit4
--
-- >>> isn't _Right (parse parse4 "test" "xyz" :: Either ParseError DecDigit)
-- True
parse4 ::
  (D4 d, CharParsing p) =>
  p d
parse4 :: p d
parse4 =
  d
forall d. D4 d => d
x4 d -> p Char -> p d
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ Char -> p Char
forall (m :: * -> *). CharParsing m => Char -> m Char
char Char
'4' p d -> String -> p d
forall (m :: * -> *) a. Parsing m => m a -> String -> m a
<?> String
"4"