Current attempts of represening natural numbers (>= 0) only have quite lose promises.
Nat is bigger than 3, why can't you subtract 1 or 2 or 3?This package contains a very strict Nat type. The actual value is present in the type.
Nat is within a minimum & maximum, try elm-nat-in-range!Setup
elm install indique/elm-n-type elm install indique/elm-n-nat-type elm install indique/elm-n-nat
import NNat exposing (NNat)
import N.Type exposing (..)
--this is N, Is, Difference, To
import N.Nat.Type as NatLets take a look at its types
n0 :
NNat --a natural number
(N N0 --zero is the exact value at compile time
Is (Difference a To a)
--we can also describe zero as the difference a - a
)
sub1 :
NNat
(N (N1Plus nMinus1)
--the exact value is nMinus1 + 1
Is (Difference a To (N1Plus nPlusAMinus1))
--we can also describe it as the difference (a + nMinus1 + 1) - a
)
-> NNat (N nMinus1 Is (Difference a To nPlusAMinus1))→ sub1 n0 is a compile-time-error!
→ We can only call sub123 for a NNat that is at least 123
You can also express things like
NNat should be at least as big as another one.safeInterval :
NNat (N first Is (Difference lastMinusFirst To last))
-> NNat (N last Is lastDifference)
-> IntervalTake a look at elm-nat-in-range & elm-n-array to see NNat in action!