summaryrefslogtreecommitdiff
path: root/src/Natural.hs
diff options
context:
space:
mode:
Diffstat (limited to 'src/Natural.hs')
-rw-r--r--src/Natural.hs21
1 files changed, 21 insertions, 0 deletions
diff --git a/src/Natural.hs b/src/Natural.hs
index 1337199..5e93e3e 100644
--- a/src/Natural.hs
+++ b/src/Natural.hs
@@ -36,6 +36,7 @@ module Natural (
, SumPositive(..)
, MaxPositive(..)
, MinPositive(..)
+, naturalPositive
, one
, one'
, successor1
@@ -543,6 +544,26 @@ instance Semigroup MinPositive where
MinPositive (Positive x) <> MinPositive (Positive y) =
MinPositive (Positive (x `min` y))
+naturalPositive ::
+ Iso' Natural (Maybe Positive)
+naturalPositive =
+ iso
+ (\(Natural n) ->
+ if n == 0 then Nothing else Just (Positive n))
+ (\x -> Natural (
+ case x of
+ Nothing ->
+ 0
+ Just (Positive n) ->
+ n)
+ )
+
+instance AsPositive Natural where
+ _Positive =
+ prism'
+ (\(Positive n) -> Natural n)
+ (\(Natural n) -> if n == 0 then Nothing else Just (Positive n))
+
one ::
Prism'
Positive