Morph for an arbitrary-sized Integer
MorphValue from an Integer
MorphRow from Chars.
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
--> NothingMorphRow from a given count of Bits
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.
Morph.OneToOnefrom anInt.Keep in mind that
Integer -> Intcan overflow sinceIntis fixed in bit size whileIntegeris not.Inverse of
Int.Morph.integer