Skip to content

Commit 8a847fb

Browse files
samthclaude
andcommitted
Add type for inclusive-range function
The inclusive-range function from racket/list was missing a type. It works like range but includes the end point. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent cf622bc commit 8a847fb

2 files changed

Lines changed: 35 additions & 0 deletions

File tree

typed-racket-lib/typed-racket/base-env/base-special-env.rkt

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,25 @@
6868
(->opt -SingleFlonum -Real [-SingleFlonum] (-lst -SingleFlonum))
6969
(->opt -InexactReal -Real [-InexactReal] (-lst -InexactReal))
7070
(->opt -Real -Real [-Real] (-lst -Real)))]
71+
;; inclusive-range
72+
[(make-template-identifier 'inclusive-range-proc 'racket/list)
73+
(cl->*
74+
(->opt -PosInt -Byte [-Int] (-lst -PosByte))
75+
(->opt -Nat -Byte [-Int] (-lst -Byte))
76+
(->opt -PosInt -Index [-Int] (-lst -PosIndex))
77+
(->opt -Nat -Index [-Int] (-lst -Index))
78+
(->opt -Nat -NonNegFixnum [-Int] (-lst -NonNegFixnum))
79+
(->opt -PosInt -Fixnum [-Nat] (-lst -PosFixnum))
80+
(->opt -Nat -Fixnum [-Nat] (-lst -NonNegFixnum))
81+
(->opt -Nat -Nat [-Int] (-lst -Nat))
82+
(->opt -PosInt -Int [-Nat] (-lst -PosInt))
83+
(->opt -Nat -Int [-Nat] (-lst -Nat))
84+
(->opt -Int -Real [-Int] (-lst -Int))
85+
(->opt -Rat -Real [-Rat] (-lst -Rat))
86+
(->opt -Flonum -Real [-Flonum] (-lst -Flonum))
87+
(->opt -SingleFlonum -Real [-SingleFlonum] (-lst -SingleFlonum))
88+
(->opt -InexactReal -Real [-InexactReal] (-lst -InexactReal))
89+
(->opt -Real -Real [-Real] (-lst -Real)))]
7190
;; unsafe-normalise-inputs
7291
[(make-template-identifier 'unsafe-normalise-inputs 'racket/private/for)
7392
(-poly (a)

typed-racket-test/unit-tests/typecheck-tests.rkt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2754,6 +2754,22 @@
27542754
[tc-e (in-combinations '(1 2 1) 2) (-seq (-lst -PosByte))]
27552755
[tc-e (permutations '(a b c d)) (-lst (-lst (one-of/c 'a 'b 'c 'd)))]
27562756
[tc-e (in-permutations '(a b c d)) (-seq (-lst (one-of/c 'a 'b 'c 'd)))]
2757+
[tc-e (inclusive-range 1 5) (-lst -PosByte)]
2758+
[tc-e (inclusive-range 1 5 2) (-lst -PosByte)]
2759+
[tc-e (inclusive-range 0 10) (-lst -Byte)]
2760+
;; Boundary conditions for inclusive-range
2761+
[tc-e (inclusive-range 5 5) (-lst -PosByte)] ; single element (start = end)
2762+
[tc-e (inclusive-range 0 0) (-lst -Byte)] ; single zero element
2763+
[tc-e (inclusive-range 0 255) (-lst -Byte)] ; full byte range
2764+
[tc-e (inclusive-range 1 1000) (-lst -PosIndex)] ; index range
2765+
[tc-e (inclusive-range 0 1000) (-lst -Index)] ; nonnegative index range
2766+
[tc-e (inclusive-range -5 5) (-lst -Int)] ; negative to positive
2767+
[tc-e (inclusive-range 1 10 3) (-lst -PosByte)] ; with step, positive
2768+
[tc-e (inclusive-range 10 1 -1) (-lst -PosByte)] ; descending range
2769+
[tc-e (inclusive-range 0.0 1.0 0.5) (-lst -Flonum)] ; flonum range
2770+
[tc-e (inclusive-range 1/2 5/2 1/2) (-lst -Rat)] ; rational range
2771+
[tc-e (inclusive-range 1 100) (-lst -PosByte)] ; max byte boundary
2772+
[tc-e (inclusive-range 1 256) (-lst -PosIndex)] ; beyond byte -> index
27572773

27582774
;; test functions which do lookup with the "wrong type", where the
27592775
;; result type shouldn't be widened to include that type

0 commit comments

Comments
 (0)