> Waldek wrote:
>> I do not think so -- in general operations are partial functions.
>> Field exports / with signature '(%, %) -> %'. Do you expect
>> no error when computing 1/0?
>
On Thu, Jun 11, 2009 at 7:14 PM, Ralf Hemmecke wrote:
> I could live with a catchable exception. And of course that must
> be properly documented. But there should be no error.
>
> In fact, the signature (%,%)->% is wrong. It's only a compromise to
>
> /: (%, NonZero(%))->%
>
> I would reserve -> for declaring total function.
+1
I agree with this! Operations which fail are not partial functions. In
the interpreter computing 1/0 should be similar to computing 1/"0".
The result should be a standard message such as:
(1) -> (1/0)
There are 12 exposed and 12 unexposed library operations named /
having 2 argument(s) but none was determined to be applicable.
Use HyperDoc Browse, or issue
)display op /
to learn more about the available operations. Perhaps
package-calling the operation or using coercions on the arguments
will allow you to apply the operation.
Cannot find a definition or applicable library operation named /
with argument type(s)
PositiveInteger
NonNegativeInteger
Perhaps you should use "@" to indicate the required return type,
or "$" to specify which version of the function you need.
The user probably intended to call
/ : (Integer,NonZero(Integer) -> Fraction(Integer)
But although the interpreter can coerce 1 in PositiveInteger into
Integer, it should not be able to automatically coerce 0 in
NonNegativeInteger to NonZero(Integer).
> Maybe there could be another arrow for partial functions.
No I don't think so. That is why we have constructions like this:
retractIfCan: Fraction(Integer) -> Union(Integer,"Failed")
And operations that can fail such as:
retract: Fraction(Integer) -> Integer
> ...
> In fact, NonZero(X) is like a subdomain of X with no (or just a few
> coercion functions) exported function.
I think NonZero(X) is exactly a subdomain of X. Associated with any
subdomain of X is a coercion and a retraction.
coerce: NonZero(X)->X
retractIfCan: X -> Union("failed", NonZero(X))
> So in implementing
>
> (x: %) / (y: NonZero(%)): % == ...
>
> there might be some y::%. Since that is the identity function, the
> compiler need not generate any function call for it.
>
> It's only that the knowledge "NonZero" is transported by this strategy.
But using / in Spad this would become a little awkward. Eg.
y:NonZero(Integer):=retractIfCan(z)
y case "failed" => error ...
x/y
Or if we wished to explicitly allow it to fail we might write:
x/retract(y)
since there are no automatic retractions or conversions.
I think that if you accept the value of strong typing then probably
this extra pedantry is worth it.
Regards,
Bill Page.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"FriCAS - computer algebra system" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/fricas-devel?hl=en
-~----------~----~----~----~------~----~------~--~---