typed-racket
typed-racket copied to clipboard
[Feature Request] support `ephemeron-hash`, remove `Weak-BoxTop`.
Hello, I noticed that racket has supported ephemeron-hash since version 8.0.0.10, so should we add corresponding types for them?
I sorted out some types and operators that may be involved:
- Types
- Strong-HashTableTop
- Strong-HashTable
- Ephemeron-HashTable
- Ephemeron-HashTableTop
- Operators
-
hash-strong?
-
hash-ephemeron?
-
make-ephemeron-hash
-
make-ephemeron-hasheq
-
make-ephemeron-hasheqv
-
in-ephemeron-hash
-
in-ephemeron-hash-pairs
-
in-ephemeron-hash-keys
-
in-ephemeron-hash-values
-
hash-copy-clear
-
hash-copy
-
unsafe-ephemeron-hash-iterate-first
-
unsafe-ephemeron-hash-iterate-next
-
unsafe-ephemeron-hash-iterate-pair
-
unsafe-ephemeron-hash-iterate-key
-
unsafe-ephemeron-hash-iterate-value
-
unsafe-ephemeron-hash-iterate-key+value
-
In addition, I noticed from https://github.com/racket/typed-racket/commit/64b062cb6f60368da80395f6974268f2c3ed50f4 that ephemeron is covariant, and weak-box doesn't seem to have a corresponding set! function. Does this mean that weak-box is also covariant? Can we remove Weak-BoxTop and support the corresponding subtype polymorphism?
Weak boxes can be modified with set-box!
Hello, @samth. I only saw make-weak-box weak-box-value weak-box? in https://docs.racket-lang.org/reference/weakbox.html . I'm not so sure how to use set-box! to modify weak-box, do I miss something?:
In racket:
Welcome to Racket v8.3 [cs].
> (define b (make-weak-box 2))
> (weak-box-value b)
2
> (set-box! b 0)
; set-box!: contract violation
; expected: (and/c box? (not/c immutable?))
; given: #<weak-box>
; [,bt for context]
in typed/racket:
Welcome to Racket v8.3 [cs].
> (: b (Weak-Boxof Natural))
> (define b (make-weak-box 8))
> (weak-box-value b)
- : (U Exact-Nonnegative-Integer False)
8
> (set-box! b 0)
; readline-input:4:0: Type Checker: Polymorphic function `set-box!' could not
; be applied to arguments:
; Argument 1:
; Expected: (Boxof a)
; Given: (Weak-Boxof Nonnegative-Integer)
; Argument 2:
; Expected: a
; Given: Zero
; in: (set-box! b 0)
; [,bt for context]
> (:print-type set-box!)
(All (a) (-> (Boxof a) a Void))