
This PR adds about half of the needed primitives and logic for reasoning about linear integer arithmetic in programs with interesting dependent types. Things have been added in a way s.t. programs will still continue to typecheck as they did, but if you want integer literals and certain operations (e.g. *,+,<,<=,=,>=,>) to include linear inequality information by default, you need to include the '#:with-linear-integer-arithmetic' keyword at the top of your module. The other features needed to get TR to be able to check things like verified vector operations will be to ajust function types so dependencies can exist between arguments and a minor tweak to get type inference to consider the symbolic objects of functions arguments. These features should be coming shortly in a future pull request.
25 lines
732 B
Racket
25 lines
732 B
Racket
#lang typed/racket #:with-linear-integer-arithmetic
|
|
|
|
|
|
(define n-1 : (Refine [x : Integer] (= x -1)) -1)
|
|
(define n0 : (Refine [x : Integer] (= x 0)) 0)
|
|
(define n0* : (Refine [x : Zero] (= x 0)) 0)
|
|
(define n1 : (Refine [x : Integer] (= x 1)) 1)
|
|
(define n2 : (Refine [x : Integer] (= x 2)) 2)
|
|
(define n2* : (Refine [x : Byte] (= x 2)) 2)
|
|
(define n3 : (Refine [x : Integer] (= x 3)) 3)
|
|
(define n42 : (Refine [x : Integer] (= x 42)) 42)
|
|
(define n42* : (Refine [x : Byte] (= x 42)) 42)
|
|
(define n42** : (Refine [x : Fixnum] (= x 42)) 42)
|
|
|
|
(define x 1)
|
|
|
|
(ann x One)
|
|
(ann x (Refine [x : One] (= x 1)))
|
|
|
|
(define y : Integer 1)
|
|
|
|
(define z : (Refine [v : Integer] (= v (* 2 y)))
|
|
(* 2 y))
|
|
|