[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 2.0.0.4 (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.
Ralf
woodpecker:~/scratch>aldor -laldor -fx aaa.as
"aaa.as", 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)
---BEGIN aaa.as
#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;
}
}
main();---END aaa.as
- [Axiom-developer] Unions in Spad, Stephen Wilson, 2007/07/08
- Re: [Axiom-developer] Unions in Spad,
Ralf Hemmecke <=
- Re: [Axiom-developer] Unions in Spad, Gabriel Dos Reis, 2007/07/11
- Re: [Axiom-developer] Unions in Spad, Bill Page, 2007/07/11
- Re: [Axiom-developer] Unions in Spad, Gabriel Dos Reis, 2007/07/11
- Re: [Axiom-developer] Unions in Spad, Bill Page, 2007/07/11
- Re: [Axiom-developer] Unions in Spad, Gabriel Dos Reis, 2007/07/11