How to declare my package's parameter properly?

4 views
Skip to first unread message

Neven Sajko

unread,
Dec 16, 2021, 3:32:06 PM12/16/21
to fricas-devel
In the process of writing some Spad packages, I realized that I need
to generalize one of them by introducing another package parameter,
because one of the types would need to be determined by the caller.

Source file: https://gitlab.com/nsajko/fricas_guessing/-/blob/master/guessing_helpers.spad

The package is GuessingHelpers, and the problematic parameter is "In".
Before I tried to turn it into a parameter, it was simply defined as
Fraction Integer, however I want to generalize the package so that In
can be either a Fraction Integer or a Fraction Polynomial Integer.

For a start, I declared In like this:

In: Join(Field, CoercibleFrom Integer, CoercibleFrom Fraction Integer)

However, this predictably fails, as my package requires In to be
coercible to Expression Integer.

If I declare In like this:

In: Join(Field, CoercibleFrom Integer, CoercibleFrom Fraction Integer,
CoercibleTo Expression Integer)

Then I can't construct the package because Fraction Integer doesn't
have the CoercibleTo Expression Integer category.

How should I declare In?

Is it possible to declare a package parameter so as to enumerate a set
of types, and saying that the parameter has to be a member of that
set? This would work for me, I could simply declare In as "either
Fraction Integer or Fraction Polynomial Integer".

Thanks,
Neven

Ralf Hemmecke

unread,
Dec 16, 2021, 4:32:09 PM12/16/21
to fricas...@googlegroups.com
Obviously that what you want does not exist.
Unfortunately, I am not a user of the Guessing package to be able to
give you a suggestion just so.

To get a rough idea of what you actually want to achieve by
GuessingHelpers it would be very helpful to know what (for example)
the function guess_func_level_1

https://gitlab.com/nsajko/fricas_guessing/-/blob/master/guessing_helpers.spad#L187

is supposed to do. Can you also give example calls (i.e. actual
parameters) for that function.

Maybe then I would be able to give a suggestion for such a helper package.

If you just want the *two* Fraction Integer and Fraction Polynomial
Integer as parameter domains, why would you want to abstract one common
category for it? You must have some more domain parameters in mind.

Ralf

Neven Sajko

unread,
Dec 17, 2021, 1:13:22 AM12/17/21
to fricas-devel
I ended up fixing this issue by moving the rat_fun_var_tran function
from the Spad package to an Input file.

I think this code has the potential to be actually useful to other
people, so I'll mention it again once I have usage examples ready.

Neven
Reply all
Reply to author
Forward
0 new messages