How to assert (listof? string?) predicate in Typed Racket

259 views Asked by At

I have a list of optional strings in a typed racket program, i.e.

statements : (Listof (Option String))

I have another function that takes a (Listof String) and I know that unless an exception is raised, all of the strings in statements are present. I'd like to assert this fact, but I don't see how to assert a predicate like (listof? string?) for example to prove this to typed racket.

1

There are 1 answers

0
ignis volens On BEST ANSWER

You can write one:

(define (listof-string? (l : (Listof Any)))
  (andmap string? l))

Then:

(define (bar (x : (Listof String)))
  x)

(define (foo (x : (Listof (Option String))))
  (bar (assert x listof-string?)))

will typecheck.