Morph
for an arbitrary-sized Integer
int : MorphOrError Integer Basics.Int error_
Morph.OneToOne
from an Int
.
Keep in mind that Integer -> Int
can overflow
since Int
is fixed in bit size while Integer
is not.
decimal : Morph Integer Decimal
Morph
from a Decimal
without digits after the decimal point.
Other possibilities of handling the fraction after the decimal points are
value : Value.Morph.Internal.MorphValue Integer
MorphValue
from an Integer
chars : MorphRow Integer Char
MorphRow
from Char
s.
You can then of course work with the Integer
type directly,
or convert it to for example an Int
import Morph
import List.Morph
import Int.Morph
-- works with natural numbers
"123"
|> Morph.toNarrow
(Int.Morph.integer
|> Morph.overRow Integer.Morph.chars
|> Morph.rowFinish
|> Morph.over List.Morph.string
)
--> Ok 123
-- works with negative numbers
"-123"
|> Morph.toNarrow
(Int.Morph.integer
|> Morph.overRow Integer.Morph.chars
|> Morph.rowFinish
|> Morph.over List.Morph.string
)
--> Ok -123
-- a decimal number is _not_ an integer
"3.14"
|> Morph.toNarrow
(Int.Morph.integer
|> Morph.overRow Integer.Morph.chars
|> Morph.rowFinish
|> Morph.over List.Morph.string
)
|> Result.toMaybe
--> Nothing
-- exponential notation, other letters, symbols etc make it fail
"3e10"
|> Morph.toNarrow
(Int.Morph.integer
|> Morph.overRow Integer.Morph.chars
|> Morph.rowFinish
|> Morph.over List.Morph.string
)
|> Result.toMaybe
--> Nothing
bits : Bytes.Endianness -> N (N.In (N.On (N.Add1 minFrom1_)) (N.Up maxX_ N.To (N.Add1 maxFrom1PlusX_))) -> MorphRow Integer Bit
MorphRow
from a given count of Bit
s
in 2's complement,
and with a given endianness.
For toBroad
: If the number is greater than the capacity possible with the given bit count,
the greatest possible value will be returned instead.