My intention is to write two functions whose signatures differ only in
the type of the second argument.

I surely could use another function name, but I think it should also
work as I have coded it below. But I couln't make that work with SPAD.
While the Aldor compiler obviously produces code that seems to work, see
below.
======================================================================
)abbrev package FOO Foo
N ==> NonNegativeInteger
Z ==> Integer
Foo(R: Ring): with
    foo: (R, N) -> R
    if R has Field then foo: (R, Z) -> R
  == add
    import from N
    foo(r: R, n: N): R == r^n
    if R has Field then
        foo(r: R, n: Z): R ==
            n < 0 => inv foo(r, qcoerce(-n)@N)
            foo(r, qcoerce(n)@N)



(1) -> foo(2,3)

   (1)  8
                                                        Type:
PositiveInteger
(2) -> foo(2,-3)
   Compiling function G732 with type Integer -> Boolean
  C-c C-c
   >> System error:
   Interactive interrupt at #x100759B7E8.

I had to interrupt the function compilation. OK, without qualification,
I could live with it. But in a fresh FriCAS I then get

(1) -> foo(2, -3)$Foo(Fraction Integer)

and my CPU runs crazy. Looks like an endless loop.

Does that mean that SPAD forces me to choose two different names for the
two exported functions? That must be a bug.

Ralf



======================================================================

---------------- faa.as
#include "axiom"
N ==> NonNegativeInteger;
Z ==> Integer;
Faa(R: Ring): with {
    faa: (R, N) -> R;
    if R has Field then faa: (R, Z) -> R;
} == add {
    import from N;
    faa(r: R, n: N): R == r^n;
    if R has Field then {
        faa(r: R, n: Z): R == {
            n < 0 => inv faa(r, qcoerce(-n)@N);
            faa(r, qcoerce(n)@N);
        }
    }
}
-----------------------------------

(1) -> faa(2,3)

   (1)  8
                                                        Type:
PositiveInteger
(2) -> faa(2,-3)
   Compiling function G728 with type Integer -> Boolean
   There are 1 exposed and 0 unexposed library operations named faa
      having 2 argument(s) but none was determined to be applicable.
      Use HyperDoc Browse, or issue
                               )display op faa
      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 faa
      with argument type(s)
                               PositiveInteger
                                   Integer

      Perhaps you should use "@" to indicate the required return type,
      or "$" to specify which version of the function you need.

(2) -> faa(2,-3)$Faa(Fraction Integer)

        1
   (2)  -
        8
                                                      Type:
Fraction(Integer)

-- 
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 post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/fricas-devel.
For more options, visit https://groups.google.com/d/optout.

Reply via email to