Domanda

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?

È stato utile?

Soluzione

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.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top