On 3/24/20, mmcdan <[email protected]> wrote:
> Hello,
>
> I'm trying to use occurrence typing for (Vectorof Symbol) or (Boxof
> Symbol).
>
> Creating a custom predicate for (Listof Symbol) seems to work:
> ---
> #lang typed/racket
>
> (: los? (-> Any Boolean : (Listof Symbol)))
> (define los?
>   (lambda (seq) (and (list? seq) (andmap symbol? seq))))
> ---
>
> However I haven't been able to create one for vectors or boxes. None of the
> things I've tried will typecheck. Any pointers?

Typed Racket can't be sure that untyped code won't change whats inside
a mutable vector or box

---
#lang racket
(define v (vector 'A))
(define (set-v!) (vector-set! v 0 0))
(provide v set-v!)

#lang typed/racket
(require/typed "path-to-untyped.rkt"
  (v : (Vectorof Any))
  (set-v! : (-> Void)))

;; suppose this worked
(: vos (-> Any Boolean : (Vectorof Symbol)))
(define (vos x) ....)

(cond
  [(vos? v)
    ;; v : (Vectorof Symbol)
    (set-v!)
    ;; v now contains an integer!
    ....]))
---

I don't know a work-around.

I was hoping it could work for (Immutable-Vectorof Symbol), but I
don't know what to use in place of `andmap`.

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/CAFUu9R6nYVHoKCFGbjD8Q%2Bs__z2Cep9rwvqRL6HyZCE5GnzyhA%40mail.gmail.com.

Reply via email to