简体   繁体   English

Typed Racket中可变参数的类型是什么?

[英]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. 我正在尝试将使用ff / vector的f32vector的Racket程序转换为Typed Racket程序,这需要通过require / typed为f32vector提供注释。 f32vector is however variadic; 然而f32vector是可变的; 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: 假设您已经为F32Vector设置了opaque类型,那么您可以编写如下类型:

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

In case you don't have an opaque type yet, you can import that like this: 如果您还没有opaque类型,可以像这样导入:

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

Of course, you can merge the clauses above into a single require/typed . 当然,您可以将上面的条款合并为一个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). 旁注:将来,Typed Racket可能还支持->*类型构造函数,该构造函数与用于编写契约的符号(包括其余参数)相匹配。 Also, hopefully we can provide a typed/ffi/vector along with the other bundled libraries. 此外,希望我们可以提供typed/ffi/vector以及其他捆绑库。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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