On Tue, May 02, 2023 at 11:13:21PM +0200, Ralf Hemmecke wrote:
> Suppose I have a union
>
> U ==> Union(elem: T, oppo :T)
>
> with the meaning that oppo represents a concept of "opposite".
>
> According to page 145 of the aldor user guide
>
> ==============
> -- This import causes both union branches to be ‘Integer’.
> import from MyType(Integer, Integer);
> fun [coef == 7];
> fun [expon == 7];
> ==============
>
> I would be able to create an element that lives in the elem or oppo side of
> the union U.
>
> How can I do that in SPAD?
AFAIK ATM there is no way. The attached patch tries to add Aldor way
to SPad compiler.
--
Waldek Hebisch
--
You received this message because you are subscribed to the Google Groups
"FriCAS - computer algebra system" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/fricas-devel/20230503005434.ncgrr55lanuvzvmo%40fricas.math.uni.wroc.pl.
--- ../trunk.pp6/src/interp/compiler.boot 2023-04-30 15:43:55.784543738 +0000
+++ compiler.boot 2023-05-02 23:50:00.189393226 +0000
@@ -736,11 +736,25 @@
eInit
[x,m,eFinal]
+comp_tagged_construct(um, tag, val, e) ==
+ ul := rest(um)
+ iter := true
+ n := 0
+ for u in ul while iter repeat
+ u is ['_:, =tag, mode] => iter := false
+ n := n + 1
+ iter => nil
+ T := comp(val, mode, e)
+ T is [cv, ., e] => [["CONS", n, cv], um, e]
+ nil
+
comp_construct1(l, m, e) ==
(y := modeIsAggregateOf("List", m, e)) =>
compList(l, ["List", CADR y], e)
(y := modeIsAggregateOf("Vector", m, e)) =>
compVector(l,["Vector",CADR y],e)
+ isTaggedUnion(m) and (l is [["DEF", [tag], [nil], val]]) =>
+ comp_tagged_construct(m, tag, val, e)
compConstruct(form is ["construct", :l], m, e) ==
(T := comp_construct1(l, m, e)) and (T' := convert(T,m)) => T'