Serge D. Mechveliani wrote:
>
> Please, could you explain the below simple issues about the domain
> system and function types in Spad ?
>
> 1. I try the possibility of mySelect2 below:
>
> -------------------------- t.spad -------------------------------
> )abbrev package FOO Foo
> Foo() : with
> mySelect1 : SetCategory -> Any
> mySelect2 : (D : SetCategory) -> D
> ==
> add
> mySelect1(D : SetCategory) : Any ==
> has(D, Field) => coerce(1 :: D) $AnyFunctions1(D)
>
> mySelect2(D : SetCategory) : D ==
> has(D, Field) => 1 :: D
> -----------------------------------------------------------------
>
> Is anything wrong in this Spad program?
> It is compiled, but then, I fail to run it in the interpreter.
> All these fail:
>
> -> mySelect1(Fraction(Integer))
> -> mySelect1(Fraction(Integer)) :: Fraction(Integer)
> -> mySelect1(Fraction(Integer)) :: Any
> -> coerce(mySelect1(Fraction(Integer))) $AnyFunctions1(Fraction(Integer))
> ...
> ,
> and the same is with mySelect2.
> How to run mySelect1 and mySelect2 ?
You hit the following three bugs/limitations:
1) Interpreter can only call functions having Type as argument type,
but can not handle general categories (in particular interpreter
can not call functions having argument which is of type
SetCategory). Spad compiler does not have this restriction.
2) Currently Spad compiler generates wrong code for 'has(D, Field)'
inside function, so once you change SetCategory to Type, intepreter
will perform call to 'mySelect1' but 'mySelect1' will fail.
Possible workaround is to pass D as a package argument and
move 'has' test outside of 'mySelect1', like:
Foo1(D : SetCategory) : with
mySelect1 : () -> Any
== add
if D has Field then
mySelect1() == coerce(1$D)$AnyFunctions1(D)
else
mySelect1() == error "unimplemented"
If you really need original interface of 'mySelect1' you can do
then:
mySelect1(D) == mySelect1()$Foo1(D)
3) Currently neither interpreter nor Spad compiler handles
signatures like 'f(D : Cat) : D'. The workaround is to put
'f' in appropriate packege having 'D' as a parameter.
--
Waldek Hebisch
[email protected]
--
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.