On Thu, May 15, 2008 at 5:57 AM, Gabriel Dos Reis wrote: > Bill Page writes: > | > | So to summarize, the pattern is something like this: > | > | if cond then > | x := 1 > | else > | x := 2.3 > | ... > | > | If this is allowed by the compiler, the question is what is the > | type of 'x' outside the scope of the 'then' and 'else' clauses? > ... > | If the scope of 'x' is intended to be global, then the type of > 'x' must be a Union. > > Union is one possiblity, another is a `real' overload. >
I agree with Waldek (in a different thread). I think the original developers of Axiom explicitly decided against variable name overloading. Do you know of any mainstream language where this is a common programming paradigm? One of the design goals of a static strongly typed language is to ensure type correctness by associating static types with variables. Allowing variable overloading by type seems to defeat this purpose - especially when it is combined with implicit typing rules. Overloading constants (including functions) however is obviously very convenient and supported in all flavors plus Aldor. > | > | x:Union(Integer,Float) > | if cond then > | x := 1 > | else > | x := 2.3 > | > | I do not see anything wrong with this proposal. It is compatible > | with only a minor change to the existing library code > > I'm not sure the change is minor: Union in Spad are different from > unions in C, in the sense that unions in Spad are tagged, which > means the the value representation of x is very different from that > of Integer or Float, and the compiler has to insert the right > coercions at the right places. One would have to assess whether > codes are generated correctly (the `scary' part of the compiler). > I have at least one example where the SPAD compiler does apparently do this correctly: http://axiom-wiki.newsynthesis.org/SandBoxLexicalScope#bottom I think we have no reason to doubt the result in more general situations - unless you have seen something 'scary' in the actual code generation part of SPAD. But in slightly more complex cases or in situations with less contextual information I do not think there is any technical problem to include tags. E.g. x:Union(c1:Integer,c2:Float) if cond then x.c1 := 1 else x.c2 := 2.3 ... x case c1 => ... Regards, Bill Page. ------------------------------------------------------------------------- This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008. http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/ _______________________________________________ open-axiom-devel mailing list open-axiom-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/open-axiom-devel