[racket] Typed Racket: Infinite Subtypes?

From: Richard Lawrence (richard.lawrence at berkeley.edu)
Date: Fri Jun 10 14:12:43 EDT 2011

Hi Racketeers,

I'm wondering if there's a way to specify a type in Typed Racket that is
an infinite subtype of an existing type. (Not sure if I'm using the
terminology correctly; by "subtype" I just mean a type whose values are a
subset of another type's values.)

For example, suppose I want to specify a type Variable that is a subtype
of Symbol, where Variable only encompasses values like: 

{'x 'x0 'x1 ... 'y 'y0 'y1 ...}

(i.e., Variable encompasses only those Symbols that, as strings, would
match #rx"[t-z][0-9]*")

Is it possible to specify such a type?  If so, what's the best way to do
this?  

And if it isn't possible, the cleanest workaround I can think of is to
tag all Variable values, like:

(define-type Variable (Pair 'var Symbol))
(define-predicate variable? Variable)

But this sort of feels more like subverting the type system than using
it, at least to my type-newbie intuitions.  Is that intuition correct?
Is there a better way?

Thanks for any advice, as always!

Best,
Richard



Posted on the users mailing list.