Reputation: 11
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.
Upvotes: 0
Views: 66
Reputation: 17203
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.
Upvotes: 0