The key is to use the for/list:
form instead since it allows you to add type annotations over the basic for/list
form to give Typed Racket more guidance. I've made a few other adjustments to get the types to line up (e.g., using filter
over filter-not
, avoiding in-range
, etc.):
#lang typed/racket
(: index-member ((Listof Any) (Listof Any) -> (Listof Index)))
(define (index-member xs ys)
(filter index?
(for/list: : (Listof Integer) ([i : Index (length xs)])
(if (member (list-ref xs i) ys) i -1))))
This actually exposes a weakness in the type of filter-not
(filter
is smarter about the type of the list it returns), which I'll look into fixing.