Skip to content

Commit 87310ff

Browse files
committed
add Boxof/Write-Read
1 parent c0d7641 commit 87310ff

File tree

3 files changed

+13
-0
lines changed

3 files changed

+13
-0
lines changed

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,17 @@ is a subtype of @racket[(Read-Only-Boxof b)] if @racket[a] is a subtype of @rack
368368
(set-box! b 5)
369369
(unbox b-read-only)]
370370

371+
@defform[(Boxof/Write-Read write-t read-t)]{
372+
A @rtech{box} that supports write operations like @racket[set-box!]
373+
taking @racket[write-t], and read operations like @racket[unbox]
374+
returning @racket[read-t]. For this type to make sense,
375+
@racket[write-t] should be a subtype of @racket[read-t].
376+
377+
The type @racket[(Boxof t)] is equivalent to
378+
@racket[(Boxof/Write-Read t t)], and the type
379+
@racket[(Read-Only-Boxof t)] is equivalent to
380+
@racket[(Boxof/Write-Read Nothing t)].}
381+
371382
@defidform[BoxTop]{is the type of a @rtech{box} with an unknown element
372383
type and is the supertype of all box types. Only read-only box operations
373384
(e.g. @racket[unbox]) are allowed on values of this type. This type

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@
173173
[Pair (-poly (a b) (-pair a b))]
174174
[Boxof (-poly (a) (-box a))]
175175
[Read-Only-Boxof (-poly (a) (-Read-Only-Boxof a))]
176+
[Boxof/Write-Read (-poly (w r) (-box w r))]
176177
[Weak-Boxof (-poly (a) (-weak-box a))]
177178
[Channelof (-poly (a) (make-Channel a))]
178179
[Async-Channelof (-poly (a) (make-Async-Channel a))]

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -452,6 +452,7 @@
452452
[(HeterogeneousVector: e) `(Vector ,@(map t->s e))]
453453
[(Box: e e) `(Boxof ,(t->s e))]
454454
[(Box: (Union: '()) e) `(Read-Only-Boxof ,(t->s e))]
455+
[(Box: e1 e2) `(Boxof/Write-Read ,(t->s e1) ,(t->s e2))]
455456
[(Weak-Box: e) `(Weak-Boxof ,(t->s e))]
456457
[(Future: e) `(Futureof ,(t->s e))]
457458
[(Channel: e) `(Channelof ,(t->s e))]

0 commit comments

Comments
 (0)