On Jun 29, 2012, at 9:12 PM, Roelof Wobben <r.wob...@home.nl> wrote: > As I understand it Vanimal is the world which can exist of a Vcat or a Vcham. > The problem is that I cannot know which one it is and if don't do a > define-struct Vanimal () I cannot check if the make the right world.
Not true. You can check whether it's a Vcat with the Vcat? function, and whether it's a Vcham with the Vcham? function. >> EITHER a VAnimal is one of two things >> OR it is a combination of two things. >> >> You can't have it both ways. -- Matthias As I explain it to my classes, you can define a new data type "by parts" -- e.g. a person HAS a forename AND a family name AND a birthdate -- or you can define a new datatype "by choices" -- e.g. a pet IS a cat OR a dog OR a fish. When you're defining a type by parts, you do a "define-struct". When you're defining a type by choices, there's no analogous definition: you just say in a comment something like "a pet is either a cat or a dog or a fish," and write code accordingly. This is a fairly common confusion for my students, and I've suggested in the past providing a "define-union" form in the student languages. It wouldn't do very much -- just define a discriminator for the new type as the "or" of the discriminators for the subtypes -- but it would provide students with a concrete syntactic hook with which to associate the concept of definition by choices. Matthias, what do you think? Stephen Bloch sbl...@adelphi.edu >> >> ____________________ Racket Users list: http://lists.racket-lang.org/users