简体   繁体   English

相较于球拍,“类型化球拍”的优势

[英]Advantages of “typed Racket” over Racket

What are the main advantages one can expect from using "#lang typed/racket" over "#lang racket"? 与“ #lang球拍”相比,使用“ #lang打字/球拍”可以期望的主要优势是什么? I could not find it in the references https://docs.racket-lang.org/ts-reference/index.html . 我在参考https://docs.racket-lang.org/ts-reference/index.html中找不到它。 Are the advantages just as for any other statically typed programming language https://en.wikipedia.org/wiki/Type_system#STATIC ? 优点是否与任何其他静态类型的编程语言一样https://en.wikipedia.org/wiki/Type_system#STATIC Is it reasonable to expect improvement in speed of compiled programs? 期望提高编译程序的速度是否合理? Is safety of programs also improved? 程序的安全性也提高了吗? Thanks for your insight. 感谢您的见解。

In the Typed Racket Guide 在《 类型球拍指南》中

7 Optimization in Typed Racket 7型拍中的优化

Typed Racket provides a type-driven optimizer that rewrites well-typed programs to potentially make them faster. Typed Racket提供了一种类型驱动的优化器,该优化器可以重写类型良好的程序,从而有可能使它们更快。 It should in no way make your programs slower or unsafe. 它绝不会使您的程序变慢或变得不安全。

Thus the type hinting can make your programs faster, but it guarantees the programs wont be slower than #lang racket as well. 因此,类型提示可以使您的程序更快,但可以保证程序也不会比#lang racket慢。

Note that this is true when you compile it with raco make or use DrRacket to make an executable. 请注意,使用raco make编译或使用DrRacket生成可执行文件时,这是正确的。 Running the code in the IDE might be slower because of the extra work the compiler does to achieve this. 在IDE中运行代码可能会比较慢,因为编译器会为此付出额外的努力。

Some of the libraries claim to be much fasted in Typed Racket. 一些库声称在Typed Racket中禁食得多。

From the Racket documentation: 从球拍文档中:

7 Matrices and Linear Algebra 7个矩阵和线性代数

Performance Warning: Matrix values are arrays, as exported by math/array. 性能警告:矩阵值是由数学/数组导出的数组。 The same performance warning applies: operations are currently 25-50 times slower in untyped Racket than in Typed Racket, due to the overhead of checking higher-order contracts. 同样适用性能警告:由于检查高阶合同的开销,当前在无类型球拍中的操作要比在无类型球拍中慢25-50倍。 We are working on it. 我们正在做这件事。

https://docs.racket-lang.org/math/matrices.html?q=matrix https://docs.racket-lang.org/math/matrices.html?q=matrix

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

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