Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 480
LogicChains Avatar asked Dec 28 '25 20:12

LogicChains


1 Answers

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.

like image 67
Asumu Takikawa Avatar answered Dec 31 '25 16:12

Asumu Takikawa



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!