Skip to content

Commit 53c2ea7

Browse files
committed
add Read-Only-Boxof
1 parent 6fa296c commit 53c2ea7

File tree

5 files changed

+11
-2
lines changed

5 files changed

+11
-2
lines changed

typed-racket-doc/typed-racket/scribblings/reference/types.scrbl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,12 @@ corresponding to @racket[trest], where @racket[bound]
354354

355355
@ex[(box "hello world")]
356356

357+
@defform[(Read-Only-Boxof t)]{A read-only @rtech{box} of @racket[t].}
358+
359+
@ex[(box-immutable "hello world")
360+
(code:comment "though this does not necessarily imply immutability:")
361+
(if (zero? (random 2)) (box "hello") (box 'hello))]
362+
357363
@defidform[BoxTop]{is the type of a @rtech{box} with an unknown element
358364
type and is the supertype of all box types. Only read-only box operations
359365
(e.g. @racket[unbox]) are allowed on values of this type. This type

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
"base-structs.rkt"
2222
racket/file
2323
(only-in racket/private/pre-base new-apply-proc)
24-
(only-in (types abbrev) [-Boolean B] [-Symbol Sym] -Flat)
24+
(only-in (types abbrev) [-Boolean B] [-Symbol Sym] -Flat -Read-Only-Boxof)
2525
(only-in (types numeric-tower) [-Number N])
2626
(only-in (rep type-rep)
2727
make-ClassTop
@@ -866,7 +866,7 @@
866866

867867
;; Section 4.12 (Boxes)
868868
[box (-poly (a) (a . -> . (-box a)))]
869-
[box-immutable (-poly (a) (a . -> . (-box a)))]
869+
[box-immutable (-poly (a) (a . -> . (-Read-Only-Boxof a)))]
870870
[unbox (-poly (a) (cl->*
871871
((-box a) . -> . a)
872872
((make-BoxTop) . -> . Univ)))]

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@
172172
[Promise (-poly (a) (-Promise a))]
173173
[Pair (-poly (a b) (-pair a b))]
174174
[Boxof (-poly (a) (-box a))]
175+
[Read-Only-Boxof (-poly (a) (-Read-Only-Boxof a))]
175176
[Weak-Boxof (-poly (a) (-weak-box a))]
176177
[Channelof (-poly (a) (make-Channel a))]
177178
[Async-Channelof (-poly (a) (make-Async-Channel a))]

typed-racket-lib/typed-racket/types/abbrev.rkt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
(define -mpair make-MPair)
5656
(define (-Param t1 [t2 t1]) (make-Param t1 t2))
5757
(define (-box t1 [t2 t1]) (make-Box t1 t2))
58+
(define (-Read-Only-Boxof t) (-box -Bottom t))
5859
(define -channel make-Channel)
5960
(define -async-channel make-Async-Channel)
6061
(define -thread-cell make-ThreadCell)

typed-racket-lib/typed-racket/types/printer.rkt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -451,6 +451,7 @@
451451
[(Vector: e) `(Vectorof ,(t->s e))]
452452
[(HeterogeneousVector: e) `(Vector ,@(map t->s e))]
453453
[(Box: e e) `(Boxof ,(t->s e))]
454+
[(Box: (Union: '()) e) `(Read-Only-Boxof ,(t->s e))]
454455
[(Weak-Box: e) `(Weak-Boxof ,(t->s e))]
455456
[(Future: e) `(Futureof ,(t->s e))]
456457
[(Channel: e) `(Channelof ,(t->s e))]

0 commit comments

Comments
 (0)