1
1
mirror of https://github.com/anoma/juvix.git synced 2024-12-01 00:04:58 +03:00
juvix/tests/negative/Internal
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
..
Positivity Change syntax for ind. data types and forbid the empty data type (#1684) 2023-01-03 13:49:04 +01:00
ExpectedExplicitArgument.juvix Change syntax for ind. data types and forbid the empty data type (#1684) 2023-01-03 13:49:04 +01:00
ExpectedExplicitPattern.juvix Change syntax for ind. data types and forbid the empty data type (#1684) 2023-01-03 13:49:04 +01:00
ExpectedFunctionType.juvix Change syntax for ind. data types and forbid the empty data type (#1684) 2023-01-03 13:49:04 +01:00
FunctionApplied.juvix Change syntax for ind. data types and forbid the empty data type (#1684) 2023-01-03 13:49:04 +01:00
FunctionPattern.juvix Change syntax for ind. data types and forbid the empty data type (#1684) 2023-01-03 13:49:04 +01:00
IdenFunctionArgsNoExplicit.juvix Fix #1693 (#1708) 2023-01-09 18:56:28 +01:00
juvix.yaml Refactor (#1420) 2022-08-03 13:20:40 +02:00
LazyBuiltin.juvix Give proper errors for incorrect application of lazy builtins (#1830) 2023-02-10 19:21:46 +01:00
LhsTooManyPatterns.juvix Change syntax for ind. data types and forbid the empty data type (#1684) 2023-01-03 13:49:04 +01:00
LiteralInteger.juvix Add builtin integer type to the surface language (#1948) 2023-04-13 08:16:49 +01:00
LiteralIntegerString.juvix Add builtin integer type to the surface language (#1948) 2023-04-13 08:16:49 +01:00
MultiWrongType.juvix Change syntax for ind. data types and forbid the empty data type (#1684) 2023-01-03 13:49:04 +01:00
PatternConstructor.juvix Change syntax for ind. data types and forbid the empty data type (#1684) 2023-01-03 13:49:04 +01:00
TooManyArguments.juvix Change syntax for ind. data types and forbid the empty data type (#1684) 2023-01-03 13:49:04 +01:00
UnsolvedMeta.juvix Change syntax for ind. data types and forbid the empty data type (#1684) 2023-01-03 13:49:04 +01:00
WrongConstructorArity.juvix Change syntax for ind. data types and forbid the empty data type (#1684) 2023-01-03 13:49:04 +01:00
WrongReturnType.juvix Change syntax for ind. data types and forbid the empty data type (#1684) 2023-01-03 13:49:04 +01:00
WrongReturnTypeParameters.juvix Change syntax for ind. data types and forbid the empty data type (#1684) 2023-01-03 13:49:04 +01:00
WrongReturnTypeTooFewArguments.juvix Change syntax for ind. data types and forbid the empty data type (#1684) 2023-01-03 13:49:04 +01:00
WrongReturnTypeTooManyArguments.juvix Change syntax for ind. data types and forbid the empty data type (#1684) 2023-01-03 13:49:04 +01:00
WrongType.juvix Change syntax for ind. data types and forbid the empty data type (#1684) 2023-01-03 13:49:04 +01:00