On Thu, May 15, 2008 at 12:50 PM, Ralf Hemmecke wrote:
>> If the scope of 'x' is intended to be global, then the type of 'x'
>> must be a Union.
>>
>>    x:Union(Integer,Float)
>>    if cond then
>>        x := 1
>>    else
>>        x := 2.3
>
> Of course that cannot work. What function pointer for multiplication should
> the compiler put in for the following
>
> x := x*x
>
> ? Union does not export a multiplication.
>
> We don't have that yet that properties of the underlying domains lift to the
> Union. Union in SPAD is rather dumb.
>

Earlier in this thread I showed that in fact this does work in the the
Axiom interpreter. Gaby argued that this is only because the
interpreter "knows" both the value and the type of x.

This also can be made to work in the compiler by "dividing the cases":

   x case Integer => x:=x*x
   x case Float => x:=x*x
   ...
   x:=x*x

Generalizing this requires the specific structure of the 'Union' to be
known to the compiler in order to generate the cases in order to
select particular operations.

Also earlier in this thread on Wed, May 14, 2008 at 5:04 PM, you wrote:
> ...
> In fact, I would rather have liked that both functions simply return a
> multivalue or a Cross(P, P), but unfortunately, that does not work in
> panAxiom.
>

I was planning to reply that in fact panAxiom does have something
similar to 'Cross' called the 'Product' domain constructor. So for
example these functions could return something of type 'Product(P,P)'
or 'DirectProduct(2,P)'  for multiple values. However the subject
drifted to other issues before I got a chance to bring this up.

But more importantly, you should notice that the 'Product' (and
'DirectProduct') domain *does* export operations lifted from the
underlying domain(s).

(1) -> x:Product(Integer,Float) := makeprod(2,3.4)

   (1)  (2,3.4)
                                                 Type: Product(Integer,Float)
(2) -> x:=x*x

   (2)  (4,11.56)
                                                 Type: Product(Integer,Float)

(3) -> )sh Product(Integer,Float)

 Product(Integer,Float) is a domain constructor.
 Abbreviation for Product is PRODUCT
 This constructor is not exposed in this frame.
------------------------------- Operations --------------------------------

 ?*? : (Integer,%) -> %                ?*? : (PositiveInteger,%) -> %
 ?*? : (%,%) -> %                      ?**? : (%,Integer) -> %
...
 1 : () -> %                           0 : () -> %
 selectfirst : % -> Integer            selectsecond : % -> Float
 size : () -> NonNegativeInteger       sup : (%,%) -> %
 zero? : % -> Boolean                  ?~=? : (%,%) -> Boolean
 ...

-------

Of course using 'Product' in this manner is also applicable in the compiler.

It is easy in principle to implement the categorical dual of 'Product'
that we might call 'Sum'. See for example some initial coding effort
here:

http://axiom-wiki.newsynthesis.org/SandBoxSum

'Sum' then is a type of 'Union' that lifts operations from it's
component domains in the manner as 'Product'.

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

Reply via email to