One would generally use case classes to create discriminated (tagged) unions (or otherwise employ type contracts). This has a similar effect and is type-safe.
In the case class tour, you can see Var, Fun an App can all be stored in something capable of holding a Term. Then pattern matching can be used to extract what has been stored and act depending upon the specific type (Var, Fun, App, etc.) matched upon. This whole process is similar to using an extra "type" flag and if/else-construct often used with C unions only, again, type-safe (and much more convenient in most cases :-)
(Actually, looking at those links is rather disappointing as it doesn't really scratch the surface :-/)
A practical example/explanation using Scala: What is an algebraic data type? It also does the nice job of showing how it relates/is handled in "lesser" languages.