简体   繁体   中英

What is the type of a variadic function in Typed Racket?

I'm attempting to convert a Racket program that uses the f32vector from ffi/vector into a Typed Racket program, which requires providing annotations for f32vector via require/typed. f32vector is however variadic; it can take a variable number of arguments, so both of the following are acceptable:

(f32vector 1.0 3.0 4.0 7.0)
(f32vector 2.0 2.1)

How would I write the type annotations for this function?

Assuming that you already have an opaque type for F32Vector , then you can write the type like this:

(require/typed ffi/vector
               [f32vector (Real * -> F32Vector)])

In case you don't have an opaque type yet, you can import that like this:

(require/typed ffi/vector
               [#:opaque F32Vector f32vector?])

Of course, you can merge the clauses above into a single require/typed .


Side note: in the future, Typed Racket will probably also support a ->* type constructor that matches the notation used for writing contracts (including rest arguments). Also, hopefully we can provide a typed/ffi/vector along with the other bundled libraries.

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