简体   繁体   中英

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

I have a list of optional strings in a typed racket program, ie

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM