On 09/26/2017 11:10 AM, oldk1331 wrote:
> Bill, I changed my mind about retractIfCan/RetractableTo, so Bill,
> Ralf and me should on the same page.

> About 'coerce : R -> Maybe R', this auto-coercion only works at 
> interpreter, right?

Yes.

> So when writing Spad, one should explicitly use 'wrap' (or 'coerce',
> but 'wrap' is more clear).

Currently, the compiler also adds auto-coercion between Rep and %, but
since I don't like this, I always make it explicit in my code. I'm not
sure whether there is also autocoercion between X and Union(X,
"failed"). Even if it made life easier, because sometimes one knows that
x is not failed and so for x1: X and x2: Union(X, "failed"), the
compiler could generate proper code for x1 + x2 by actually translating
that into x1 + retract(x2)@X, I'd still like to be explicit.

It's true that x1 + x2 is more readable and that x2 and retract(x2)@X
are essentially the same thing, but for me to opt for an ommision of
retract, I would want a special type (even call it Maybe(X) or
Union(X,"failed")), that is part of the language description. Otherwise
all types should be treated in the same way, so one must explicitly
write the coercion function in the source code.

> About 'retract : Maybe R -> R', it should do error checking, as
> other 'retract' do.

Really? Yes, it can, but it is a matter of specification. If you declare
that retract(x) is only applicable if not(failed?(x)) holds, then there
is no need for an additional error checking. Such error checking would
only be a safety net, but not necessary by specification.

> And when writing Spad, one can use 'unwrap(x)'
> or 'retract(x)', but not 'x::R' like we used to when using
> Union("failed",...), or should we?

Yes, x::R would look nicer, but I don't think that retract(x) is so bad.
And retract is also an indicator that the programmer should have taken
care that x is indeed not "failed".

> By adding 'convert : Maybe R -> R' (with error checking)?

What do you gain? (Of course, all depends on the specification.) But,
why have an additional error check if the programmer already knows that
nothing can go wrong? And if you have error checking what would your
return? Probably error "some message". That aborts the program, because
there is no way to catch such an error. Without error checking the
program probably also crashes, only that the way how it crashes is not
defined.

> A lot of current code use :: to retract from Union("failed", R) to
> R, I experienced that in the previous commit.

> I'm inclined to have this '::' conversion,  because '::' is still
> explicit.

Yes, ::R doesn't look so bad. AFAIK, the rule is that :: translates into
"coerce", not "retract" (in the compiler; the interpreter is a different
thing). Unfortunately, SPAD breaks that convention with the Union type.
I agree, that ::R looks nice, but I also like to have no exceptions to a
general rule.

Ralf

-- 
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 fricas-devel+unsubscr...@googlegroups.com.
To post to this group, send email to fricas-devel@googlegroups.com.
Visit this group at https://groups.google.com/group/fricas-devel.
For more options, visit https://groups.google.com/d/optout.

Reply via email to