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