mirror of
https://github.com/anoma/juvix.git
synced 2024-12-12 14:28:08 +03:00
ea09ec3068
This PR adds a builtin integer type to the surface language that is compiled to the backend integer type. ## Inductive definition The `Int` type is defined in the standard library as: ``` builtin int type Int := | --- ofNat n represents the integer n ofNat : Nat -> Int | --- negSuc n represents the integer -(n + 1) negSuc : Nat -> Int; ``` ## New builtin functions defined in the standard library ``` intToString : Int -> String; + : Int -> Int -> Int; neg : Int -> Int; * : Int -> Int -> Int; - : Int -> Int -> Int; div : Int -> Int -> Int; mod : Int -> Int -> Int; == : Int -> Int -> Bool; <= : Int -> Int -> Bool; < : Int -> Int -> Bool; ``` Additional builtins required in the definition of the other builtins: ``` negNat : Nat -> Int; intSubNat : Nat -> Nat -> Int; nonNeg : Int -> Bool; ``` ## REPL types of literals In the REPL, non-negative integer literals have the inferred type `Nat`, negative integer literals have the inferred type `Int`. ``` Stdlib.Prelude> :t 1 Nat Stdlib.Prelude> :t -1 Int :t let x : Int := 1 in x Int ``` ## The standard library Prelude The definitions of `*`, `+`, `div` and `mod` are not exported from the standard library prelude as these would conflict with the definitions from `Stdlib.Data.Nat`. Stdlib.Prelude ``` open import Stdlib.Data.Int hiding {+;*;div;mod} public; ``` * Closes https://github.com/anoma/juvix/issues/1679 * Closes https://github.com/anoma/juvix/issues/1984 --------- Co-authored-by: Lukasz Czajka <lukasz@heliax.dev> |
||
---|---|---|
.. | ||
265 | ||
272 | ||
BuiltinsMultiImport | ||
BuiltinsMultiOpenImport | ||
Dependencies | ||
Imports | ||
ImportShadow | ||
Internal | ||
issue1333 | ||
issue1466 | ||
issue1693 | ||
issue1731 | ||
issue1879 | ||
QualifiedConstructor | ||
QualifiedSymbol | ||
QualifiedSymbol2 | ||
Reachability | ||
StdlibImport | ||
StdlibList | ||
Termination | ||
Ape.juvix | ||
Axiom.juvix | ||
Builtins.juvix | ||
BuiltinsBool.juvix | ||
Format.juvix | ||
Inductive.juvix | ||
InductivePipes.juvix | ||
Judoc.juvix | ||
juvix.yaml | ||
LetShadow.juvix | ||
Literals.juvix | ||
MultiParams.juvix | ||
MutualLet.juvix | ||
Operators.juvix | ||
Parsing.juvix | ||
Polymorphism.juvix | ||
PolymorphismHoles.juvix | ||
ShadowPublicOpen.juvix | ||
SignatureWithBody.juvix | ||
Symbols.juvix | ||
TypeAlias.juvix |