1
1
mirror of https://github.com/anoma/juvix.git synced 2024-12-01 00:04:58 +03:00
juvix/tests/negative
Paul Cadman ea09ec3068
Add builtin integer type to the surface language (#1948)
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>
2023-04-13 08:16:49 +01:00
..
230 Change syntax for ind. data types and forbid the empty data type (#1684) 2023-01-03 13:49:04 +01:00
258 Change syntax for ind. data types and forbid the empty data type (#1684) 2023-01-03 13:49:04 +01:00
265 Change syntax for ind. data types and forbid the empty data type (#1684) 2023-01-03 13:49:04 +01:00
BindGroupConflict Change syntax for ind. data types and forbid the empty data type (#1684) 2023-01-03 13:49:04 +01:00
ImportCycle Rename MiniJuvix to Juvix (#259) 2022-07-08 13:59:45 +02:00
Internal Add builtin integer type to the surface language (#1948) 2023-04-13 08:16:49 +01:00
issue1337 Change syntax for ind. data types and forbid the empty data type (#1684) 2023-01-03 13:49:04 +01:00
issue1344 Change syntax for ind. data types and forbid the empty data type (#1684) 2023-01-03 13:49:04 +01:00
issue1700 Fix inference loop (#1726) 2023-01-17 13:28:38 +01:00
StdlibConflict Rename MiniJuvix to Juvix (#259) 2022-07-08 13:59:45 +02:00
Termination Change syntax for ind. data types and forbid the empty data type (#1684) 2023-01-03 13:49:04 +01:00
AmbiguousConstructor.juvix Change syntax for ind. data types and forbid the empty data type (#1684) 2023-01-03 13:49:04 +01:00
AmbiguousExport.juvix Change syntax for ind. data types and forbid the empty data type (#1684) 2023-01-03 13:49:04 +01:00
AmbiguousModule.juvix Rename MiniJuvix to Juvix (#259) 2022-07-08 13:59:45 +02:00
AmbiguousSymbol.juvix Change syntax for ind. data types and forbid the empty data type (#1684) 2023-01-03 13:49:04 +01:00
AppLeftImplicit.juvix remove ≔ from the language and replace it by := (#1563) 2022-09-30 10:55:32 +10:00
AsPatternAlias.juvix Improve As-Pattern parsing (#1603) 2022-11-03 10:02:22 +01:00
ConstructorExpectedLeftApplication.juvix Implement some error messages (#1396) (#1400) 2022-07-20 16:24:03 +02:00
DuplicateClause.juvix Allow type signatures to have a body (#1785) 2023-01-31 08:46:53 +00:00
DuplicateFixity.juvix Rename MiniJuvix to Juvix (#259) 2022-07-08 13:59:45 +02:00
DuplicateInductiveParameterName.juvix Change syntax for ind. data types and forbid the empty data type (#1684) 2023-01-03 13:49:04 +01:00
ImplicitPatternLeftApplication.juvix Implement some error messages (#1396) (#1400) 2022-07-20 16:24:03 +02:00
InfixError.juvix Rename MiniJuvix to Juvix (#259) 2022-07-08 13:59:45 +02:00
InfixErrorP.juvix Change syntax for ind. data types and forbid the empty data type (#1684) 2023-01-03 13:49:04 +01:00
juvix.yaml Rename MiniJuvix to Juvix (#259) 2022-07-08 13:59:45 +02:00
LacksFunctionClause.juvix Rename MiniJuvix to Juvix (#259) 2022-07-08 13:59:45 +02:00
LacksTypeSig2.juvix Allow shadowing local variables with let function definitions (#1847) 2023-02-22 10:26:54 +01:00
LacksTypeSig.juvix remove ≔ from the language and replace it by := (#1563) 2022-09-30 10:55:32 +10:00
LetMissingClause.juvix Remove braces from let expressions (#1790) 2023-02-01 19:22:43 +01:00
ModuleNotInScope.juvix Rename MiniJuvix to Juvix (#259) 2022-07-08 13:59:45 +02:00
MultipleDeclarations.juvix Rename MiniJuvix to Juvix (#259) 2022-07-08 13:59:45 +02:00
MultipleExportConflict.juvix Rename MiniJuvix to Juvix (#259) 2022-07-08 13:59:45 +02:00
NestedAsPatterns.juvix Improve As-Pattern parsing (#1603) 2022-11-03 10:02:22 +01:00
NestedPatternBraces.juvix remove ≔ from the language and replace it by := (#1563) 2022-09-30 10:55:32 +10:00
NotInScope.juvix Rename MiniJuvix to Juvix (#259) 2022-07-08 13:59:45 +02:00
QualSymNotInScope.juvix Rename MiniJuvix to Juvix (#259) 2022-07-08 13:59:45 +02:00
Tab.juvix Disallow tab characters as spaces (#1523) 2022-09-07 13:59:41 +02:00
UnusedOperatorDef.juvix Rename MiniJuvix to Juvix (#259) 2022-07-08 13:59:45 +02:00
WrongModuleName.juvix Rename MiniJuvix to Juvix (#259) 2022-07-08 13:59:45 +02:00