[plt-scheme] define-union

From: Stephen Bloch (sbloch at adelphi.edu)
Date: Fri Apr 18 14:20:05 EDT 2003

I mentioned this on the plt-edu list on Dec. 20, and I think Marvin 
Hernandez replied -- with a much more powerful and general mechanism 
which, however, is more powerful and general than I want to introduce 
to my non-majors after six weeks.  So would one of you PLT hackers be 
so kind as to write me a "define-union"?  I'm sure I could figure out 
how to do it myself eventually, and I do need to learn define-syntax 
eventually, but I'm also sure you folks could do it much more easily 
and quickly.

(define-struct foo (a b))
(define-struct bar (c d e))
(define-union snark (foo bar number))

Semantics: checks that foo, bar, and number are in fact known types, 
with one-place discriminator predicates foo?, bar?, and number? 
respectively, and does the equivalent of
(define (snark? x)
    (or (foo? x) (bar? x) (number? x)))

Obviously, it's not NEEDED in order to work with mixed types, but I 
think my students would have an easier time thinking about mixed 
types if they had some syntax analogous to define-struct to which to 
attach the concept.
                                      Stephen Bloch
                                   Math/CS Department
                                   Adelphi University

Posted on the users mailing list.