We go on where we left off in elm-n-nat-type.
You might also want a function, where one
NaturalNatshould be at least as big as another one.
unsafeInterval : NaturalNumber first -> NaturalNumber maybeMoreThanFirst -> Intervalimport N.Nat.Type exposing (..)
import N.Type exposing (..)
--we don't expose the constructor
type NNat n =
NNat Int
zero : NNat (N Nat0 Is (Diffence a To a))
zero =
NNat one
add1 :
NNat (N n Is (Difference a To nPlusA))
-> NNat (N (Nat1Plus n) Is (Difference a To (Nat1Plus nPlusA))
add1 (NNat int) =
NNat (int + 1)We can now see if the difference between two values is a certain value!
We want to promise that
last == first + the interval lengthwhich means
first == last - the interval length→ N first Is (Difference intervalLength To last) is our final type 🔥!
safeInterval :
NNat (N first Is (Difference maybeMore To last))
-> NNat last describesADelta
-> IntervalThis package together with elm-n-nat-type is the foundation of elm-n-nat, elm-nat-in-range, elm-array-in-range.
Take a closer look at those packages to see N.Type in action!