简体   繁体   中英

Creating a new numeric type in Typed Racket

Noob Racket/ Typed Racket user here.

I want to define a custom type which represents any floating number from 0 to 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.

The numeric tower is... interesting. For a good time, take a look at

(:print-type +)

... in the interactions window or the command-line 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.

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).

I should be clear that I'm not familiar with the limits of TR's refinement type system.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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