[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Axiom-developer] Unions in Spad

From: Ralf Hemmecke
Subject: Re: [Axiom-developer] Unions in Spad
Date: Sun, 08 Jul 2007 23:29:58 +0200
User-agent: Thunderbird (X11/20070604)

Hello Stephen,

Regular Unions do not have tags associated with branches. For example:

      Union(Integer, String)

New Unions have tags, as in

      Union(int: Integer, str: String)

SPAD seems to allow

u: Union(Integer, String) := ...
if u case Integer then ...

I am not aware of the fact that Aldor can do this. And in the Aldor User Guide I have only found tagged unions.

How does now actually distinguish branches. My code above was actually only a guess. I have no idea whether that works in SPAD. In Aldor it doesn't.


woodpecker:~/scratch>aldor -laldor -fx
"", line 13:         if u case MachineInteger then {
[L13 C19] #1 (Error) Argument 2 of `case' did not match any possible parameter type.
    The rejected type is Join(
                PrimitiveType with
    Expected one of:
      -- Enumeration(MachineInteger: Type)
      -- Enumeration(String: Type)

#include "aldor"
#include "aldorio"
macro I == MachineInteger;
main(): () == {
        import from I, String;
        U == Union(MachineInteger, String);
        import from U;
        i: I := 2;
        s: String := "I am a string";
        ui: U := union i;
        us: U := union s;
        u: U := if odd? random(10) then ui else us;
        if u case MachineInteger then {
                stdout << "Integer: " << newline;
        } else {
                stdout << "String: " << newline;

reply via email to

[Prev in Thread] Current Thread [Next in Thread]