What is the type of variational function in Typed Racket?

I am trying to convert a Racket program that uses f32vector from ffi / vector to a Typed Racket program that requires the provision of annotations for f32vector via require / typed. f32vector, however, is variable; it can take a variable number of arguments, so both of them are acceptable:

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

How do I write type annotations for this function?

+3
source share
1 answer

Assuming you already have an opaque type for F32Vector, you can write this type:

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

If you don't have an opaque type yet, you can import it as follows:

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

Of course, you can combine the sentences above into one require/typed.


: Typed Racket, , ->*, , ( ). , typed/ffi/vector .

+3

All Articles