summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorqfpl <>2018-08-06 00:57:00 (GMT)
committerhdiff <hdiff@hdiff.luite.com>2018-08-06 00:57:00 (GMT)
commit500df0926d60120c7106157f1b27ad3115ed47e7 (patch)
tree34d1e9e2182d375b6f789550b46146c3daea531f
parent97128aa3f973a42d18b642d8722be4c9d9d030b1 (diff)
version 0.1.0.20.1.0.2
-rw-r--r--changelog.md8
-rw-r--r--natural.cabal2
-rw-r--r--src/Natural.hs36
3 files changed, 43 insertions, 3 deletions
diff --git a/changelog.md b/changelog.md
index e54d481..2b41136 100644
--- a/changelog.md
+++ b/changelog.md
@@ -1,6 +1,12 @@
+0.1.0.2
+
+* add `minus` function.
+* add `one` and `one'` values.
+* add `list` iso.
+
0.1.0.1
-* Add support for GHC 7.10 and GHC 8.4
+* Add support for GHC 7.10 and GHC 8.4.
0.1.0.0
diff --git a/natural.cabal b/natural.cabal
index 047b6e7..0f3e966 100644
--- a/natural.cabal
+++ b/natural.cabal
@@ -1,7 +1,7 @@
-- documentation, see http://haskell.org/cabal/users-guide/
name: natural
-version: 0.1.0.1
+version: 0.1.0.2
synopsis: Natural number
description:
<<http://i.imgur.com/uZnp9ke.png>>
diff --git a/src/Natural.hs b/src/Natural.hs
index d202382..c68e936 100644
--- a/src/Natural.hs
+++ b/src/Natural.hs
@@ -12,6 +12,8 @@ module Natural(
, MinNatural(..)
, zero
, zero'
+, one
+, one'
, successor
, successor'
, length
@@ -24,11 +26,13 @@ module Natural(
, findIndex
, elemIndices
, elemIndex
+, minus
+, list
) where
import Control.Applicative(Const)
import Control.Category((.), id)
-import Control.Lens(Wrapped(_Wrapped', Unwrapped), Rewrapped, Prism', Lens', (^?), ( # ), _Wrapped, prism', iso)
+import Control.Lens(Wrapped(_Wrapped', Unwrapped), Rewrapped, Prism', Lens', Iso', (^?), ( # ), _Wrapped, prism', iso)
import Control.Monad((>>=))
import Data.Bool(Bool)
import Data.Eq(Eq((==)))
@@ -211,6 +215,20 @@ zero' ::
zero' =
zero # ()
+one ::
+ Prism'
+ Natural
+ ()
+one =
+ prism'
+ (\() -> Natural 1)
+ (\(Natural n) -> if n == 1 then Nothing else Just ())
+
+one' ::
+ Natural
+one' =
+ one # ()
+
successor ::
Prism'
Natural
@@ -311,3 +329,19 @@ elemIndex ::
-> Maybe Natural
elemIndex =
findIndex . (==)
+
+minus ::
+ Natural
+ -> Natural
+ -> Natural
+minus (Natural x) (Natural y) =
+ Natural (if x < y then 0 else x - y)
+
+list ::
+ Iso'
+ Natural
+ [()]
+list =
+ iso
+ (\n -> replicate n ())
+ length