Idris2-boot/src/Text/Quantity.idr
Edwin Brady 082bc5cd54 Initial structure
TT types and values, some text manipulation, basics of Core
2019-03-07 23:04:55 +00:00

39 lines
895 B
Idris

module Text.Quantity
%access public export
%default total
record Quantity where
constructor Qty
min : Nat
max : Maybe Nat
Show Quantity where
show (Qty Z Nothing) = "*"
show (Qty Z (Just (S Z))) = "?"
show (Qty (S Z) Nothing) = "+"
show (Qty min max) = "{" ++ show min ++ showMax ++ "}"
where
showMax : String
showMax = case max of
Nothing => ","
Just max' => if min == max'
then ""
else "," ++ show max'
between : Nat -> Nat -> Quantity
between min max = Qty min (Just max)
atLeast : Nat -> Quantity
atLeast min = Qty min Nothing
atMost : Nat -> Quantity
atMost max = Qty 0 (Just max)
exactly : Nat -> Quantity
exactly n = Qty n (Just n)
inOrder : Quantity -> Bool
inOrder (Qty min Nothing) = True
inOrder (Qty min (Just max)) = min <= max