-
-
Couldn't load subscription status.
- Fork 104
Open
Description
Currently, both treelist-ref and treelist-set take an index of type Index instead of Integer, which is not only inconsistent with how other collections handle indices (e.g. string-ref, vector-ref, and vector-set! all take an Integer as their argument to index into the container), but also makes it difficult to do arithmetic on indices.
#lang typed/racket
(require racket/treelist)
(: idx Index)
(define idx 0)
(: tr (TreeListof String))
(define tr (treelist "apple" "orange"))
;; okay
(treelist-ref tr idx)
;; not okay, (add1 idx) is no longer an Index
(treelist-ref tr (add1 idx))
;; okay, but annoying
(let ([new-idx (add1 idx)])
(if (index? new-idx)
(treelist-ref tr new-idx)
(error "not an index")))The same issue doesn't apply if those functions took Integer as inputs instead.
Metadata
Metadata
Assignees
Labels
No labels