casa-reoc-0.1.0.0: src/ReOC/Primitive/PassMark.hs
{-# LANGUAGE DeriveLift #-}
{-# OPTIONS_GHC -Wall #-}
{- | The pass mark of a theory examination of RePL training: a whole
percentage from 70 to 100. The least pass mark of 70% is taken from general
knowledge of the Part 101 MOS, which is not among the sources of this package,
and must be checked against it.
The constructor is not exported (see "ReOC.Primitive.Text1"). A
@PassMark@ is built with the prism '_PassMark' or with
'passMarkLiteral'.
-}
module ReOC.Primitive.PassMark (
PassMark,
_PassMark,
passMarkNatural,
passMarkLiteral,
) where
import Control.Lens (Prism', preview, prism')
import Language.Haskell.TH.Syntax (Code (..), Lift, Q, liftTyped)
import Numeric.Natural (Natural)
{- $setup
>>> import Control.Lens ((^?))
-}
-- | A pass mark, from 70% to 100%.
newtype PassMark
= PassMark Natural
deriving (Eq, Ord, Show, Lift)
{- | A pass mark, from 70% to 100%.
>>> (80 :: Natural) ^? _PassMark
Just (PassMark 80)
>>> (69 :: Natural) ^? _PassMark
Nothing
-}
_PassMark :: Prism' Natural PassMark
_PassMark =
prism'
passMarkNatural
(\n -> if n >= 70 && n <= 100 then Just (PassMark n) else Nothing)
-- | The percentage.
passMarkNatural :: PassMark -> Natural
passMarkNatural (PassMark n) =
n
{- | A @PassMark@ literal, checked when the program is compiled:
> $$(passMarkLiteral 80)
-}
passMarkLiteral :: Natural -> Code Q PassMark
passMarkLiteral n =
maybe
(Code (fail ("passMarkLiteral: not from 70 to 100: " <> show n)))
liftTyped
(preview _PassMark n)