Ralf Hemmecke wrote:
>
> 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.
AFAICS you hit Spad feature called operation subsumption. According
to Davenport paper, given foo: (R, N) -> R and foo: (R, Z) -> R
the first one is subsumed by the second, that is the secend
one should be called even if argument is of type N. This is
because N is a subtype of Z. In his paper Davenport noted that
there was some disagreement about this feature...
--
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 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.