简体   繁体   English

在 Typed Racket 中创建新的数字类型

[英]Creating a new numeric type in Typed Racket

Noob Racket/ Typed Racket user here. Noob Racket/Typed Racket 用户在这里。

I want to define a custom type which represents any floating number from 0 to 1.我想定义一个自定义类型,它表示从 0 到 1 的任何浮点数。

Does anyone know how to create such a type?有谁知道如何创建这样的类型?

Thank you for the help!感谢您的帮助!

Searched the Typed Racket documentation, but could not find the source code for some types such as Positive-Real.搜索了 Typed Racket 文档,但找不到某些类型的源代码,例如 Positive-Real。

The numeric tower is... interesting.数字塔……很有趣。 For a good time, take a look at过得好,看看

(:print-type +)

... in the interactions window or the command-line REPL. ...在交互窗口或命令行 REPL 中。 Basically, there are a huge number of facts about arithmetic baked into the existing number system.基本上,现有的数字系统中包含了大量关于算术的事实。 If you wanted, say, a new numeric type for floats between 0 and 1 and for TR to be able to infer that (say) the product of two such numbers was another float between 0 and 1, I think you'd be out of luck.比方说,如果你想要一个新的数字类型,用于 0 和 1 之间的浮点数,并且 TR 能够推断(比如说)两个这样的数字的乘积是另一个 0 和 1 之间的浮点数,我想你会出局运气。

Ben Greenman or Sam Tobin-Hochstadt (or a number of others) would be able to give you a more authoritative answer on the racket discourse or the racket discord (see https://www.racket-lang.org for links). Ben Greenman 或 Sam Tobin-Hochstadt(或其他一些人)将能够为您提供有关球拍话语或球拍不和谐的更权威的答案(有关链接,请参见https://www.racket-lang.org )。

I should be clear that I'm not familiar with the limits of TR's refinement type system.我应该清楚,我不熟悉 TR 的细化类型系统的限制。

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

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