lue-bird/elm-morph/1.1.1

NOTE: the latest version is 3.0.1

Natural

Arbitrary-size, safe natural number ≥ 0. See also Natural.Morph

type Natural
= N0
| AtLeast1 AtLeast1

Whole number (integer) ≥ 0 of arbitrary precision. Either 0 directly or a positive number represented by the bit I followed by some Bits

Why does the type look like this?

If you need a natural number representation with a specific number of bits, you can try

ArraySized Bit (Exactly (On bitLength))

For larger numbers, where you want to allow numbers of arbitrary precision, only our version can enforce that == always gives the correct answer, since the ArraySized could be constructed with leading Os!

type alias AtLeast1 =
RecordWithoutConstructorFunction { bitsAfterI : List Bit }

Positive natural number, can be arbitrarily large

create

fromN : N range_ -> Natural

transform

toN : Natural -> N (Min (Up0 minX_))

Convert to a natural number of type N

Keep in mind that this can overflow since N is fixed in bit size just like Int while Natural is not.

The type is rarely useful in its current state, as the only thing you can do is convert from and to other types.

This is enough for my use-cases but feel free to PR or open an issue if you'd like to see support for arbitrary-precision arithmetic like addition, multiplication, ...