3 ms·
These are called sub-types or pattern types, and they are not in the language. But they are something I would love to have. You can’t emulate them with GAT unfo
by celeritascelery 4y ago
These are called sub-types or pattern types, and they are not in the language. But they are something I would love to have. You can’t emulate them with GAT unfortunately.
https://cohost.org/oli-obk/post/165584-ranged-integers-via https://cohost.org/oli-obk/post/165584-ranged-integers-via
- karmakaze 4y agoI've not heard this called sub- or pattern types before. Perhaps the rfc syntax is complicating the discussion. We have struct and tuple in Rust where tuple is an ad-hoc/anonymous struct where only the number and order of member types matter. We have enum which are nominal types. We don't have the ad-hoc/anonymous version of them where only the set of possible types matter. In TypeScript, F#/OCaml they would be like x: TypeA|TypeB
- celeritascelery 4y agoI first heard about this feature in OCaml. I got the name subtype or pattern type from this thread: https://internals.rust-lang.org/t/thoughts-on-pattern-types-and-subtyping/17675 https://internals.rust-lang.org/t/thoughts-on-pattern-types-...
- karmakaze 4y agoThanks for the reference. I can see how values of type A could be considered as a subset of values of type A|B, but I think the 'any value of type A' subset of type A|B is more related to types and less about restricting the range/set of values for a type.