Hi,
----------------------------------------------------------------------
1) without the signature elt: (%, PositiveInteger) -> Coef
----------------------------------------------------------------------
(12) -> chk(a, 1)
(12) 1784
Type: PositiveInteger
That looks OK.
----------------------------------------------------------------------
2) including the signature elt: (%, PositiveInteger) -> Coef (but
without it's implementation)
----------------------------------------------------------------------
Unfortunately, this comiles. :-( Please report that here.
http://sourceforge.net/tracker/?atid=972421&group_id=200168
(Please login first.)
(15) -> chk(a, 1)
Function: ?.? : (%,PositiveInteger) -> Integer is missing from domain:
HiThere(Integer)
Internal Error
The function elt with signature (Integer)$(PositiveInteger) is missing
from domain HiThere(Integer)
Note that chk shouldn't call elt$HiThere(Integer) at all!
Somehow true, but that code shouldn't have compiled, anyway.
----------------------------------------------------------------------
3) including the signature elt: (%, PositiveInteger) -> Coef and it's
implementation
----------------------------------------------------------------------
(17) -> chk(a, 1)
>> System error:
invalid number of arguments: 2
----------------------------------------------------------------------
I have replace the line x:Coef := f n by
x: Coef := (f$FUN)(n)
Now look at the error.
compiling exported chk : ($,PositiveInteger) -> Coef
****** Domain: (Mapping Coef (PositiveInteger)) already in scope
****** Domain: (Mapping Coef (PositiveInteger)) already in scope
****** Domain: (Mapping Coef (PositiveInteger)) already in scope
****** Domain: (Mapping Coef (PositiveInteger)) already in scope
****** Domain: (Mapping Coef (PositiveInteger)) already in scope
****** Domain: (Mapping Coef (PositiveInteger)) already in scope
****** Domain: (Mapping Coef (PositiveInteger)) already in scope
****** Domain: (Mapping Coef (PositiveInteger)) already in scope
****** Domain: (Mapping Coef (PositiveInteger)) already in scope
****** Domain: (Mapping Coef (PositiveInteger)) already in scope
****** Domain: (Mapping Coef (PositiveInteger)) already in scope
****** comp fails at level 3 with expression: ******
error in function chk
(SEQ
(LET (|:| |f| (|Mapping| |Coef| (|PositiveInteger|)))
(|pretend| |a| (|Mapping| |Coef| (|PositiveInteger|))))
(|print| (+ (|::| "--===1== " (|OutputForm|)) (|::| |n| (|OutputForm|))))
(LET (|:| |x| |Coef|)
| << |
((|elt| (|Mapping| |Coef| (|PositiveInteger|)) |f|) |n|)
| >> |)
(|print| (+ (|::| "--===2== " (|OutputForm|)) (|::| |n| (|OutputForm|))))
(|exit| 1 |x|))
****** level 3 ******
$x:= ((elt (Mapping Coef (PositiveInteger)) f) n)
$m:= $EmptyMode
$f:=
((((|x| #) (|f| # #) (|n| # #) (|a| # #) ...)
((|rep| #) (~= #) (= #) (|coerce| #) ...)
((|per| #) (|Rep| #) (FUN #) (|$Information| #) ...)))
>> Apparent user error:
NoValueMode
is an unknown mode
Surprise, surprise. There appears an "elt" here.
That is what I suspected. In Aldor the equivalent of "elt" is called
"apply". In Aldor there is a difference between f(n) (i.e. function
application) and apply(f, n).
In Aldor f(n) applies the *function* f to an argument f. Now if f (and
only then) is not of a function type that can be applied to the argument
n (types must match), then Aldor checks all "apply" functions that are
in scope whether there is something so that apply(f, n) typechecks and
the result type matches the context.
Obviously in SPAD there is not such a distiction. Honestly, I have no
clear picture of which approach is the better one.
See attached file too support what I just said.
Output is...
aldor -grun -laldor hi.as
chk(a, 1)=1235
a(1) =11235
Interestingly this program is an instance of a case where replacing "Rep
==>" by "Rep ==" makes the current aldor compiler to refuse the program.
Also not that "Rep" is just a name as any other.
So with appropriate macro definitions for rep and per, I could replace
"Rep" by "Blah". ;-)
Ralf
---rhxBEGIN hi.as
#include "aldorio"
Ring ==> PrimitiveType;
PositiveInteger ==> Integer;
HiThere(Coef: Ring): with {
coerce: (PositiveInteger -> Coef) -> %;
chk: (%, PositiveInteger) -> Coef;
apply: (%, PositiveInteger) -> Coef;
} == add {
Rep ==> PositiveInteger -> Coef;
coerce(f: Rep): % == per f;
chk(a: %, n: PositiveInteger): Coef == (rep a) n;
apply(a: %, n: PositiveInteger): Coef == (rep a)(n+10000);
}
main(): () == {
import from PositiveInteger;
h(n: PositiveInteger): PositiveInteger == n + 1234;
a: HiThere(PositiveInteger) := h :: HiThere(PositiveInteger);
stdout << "chk(a, 1)=" << chk(a, 1) << newline;
stdout << "a(1) =" << a(1) << newline;
}
main()
---rhxEND hi.as
--
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.