Hi,
another thing that seems weird, but I'm not sure ... in the code below,
it calls the expected (specified) version of pr_node. If you use the
commented out version of the pr_treeD definition where it specifies the
type, it actually passes the pr_node of (int*aNode[T]) routine, even
though the code says to pass "pr_node of (int*aNode[double]).
//------------------
// this version doesn't refer to the generic parts of the aNode[T]
proc pr_node[T] (d:int, x:aNode[T]) {
print$ " " * d;
print$ f"B(%d)\n" (x.index);
}
proc pr_node (d:int, x:aNode[double]) {
print$ " " * d;
print$ f"B(%d=%.1f)\n" (x.index, x.element);
}
//proc pr_treeD[double] (tree:avl[aNode[double]]) {
proc pr_treeD (tree:avl[aNode[double]]) {
Avl::iter[aNode[double]] (pr_node of (int*aNode[double]), tree);
}
//----------------
Jonathan.
#import <flx.flxh>;
open List;
open C_hack;
open Avl;
open Double;
open VArray;
module VArray {
class vArray[T] {
//var cmp:T*T->int;
var arr:avl[aNode[T]];
var dflt:T;
//ctor(default:T, compare:T*T->int) {
ctor(value:T) {
//cmp = compare;
dflt = value;
arr = Nil[aNode[T]];
}
}
class aNode[T] {
var index:int;
var element:T;
ctor(idx:int, x:T) {
index = idx;
element = x;
}
}
fun cmp[T](x:aNode[T], y:aNode[T]) = {
return cmp(x.index, y.index);
}
noinline proc adder[T](arr:vArray[T], i:int, x:T) {
var z <- new aNode[T](i, x);
arr.arr = insert(arr.arr, z, cmp of (aNode[T]*aNode[T]));
}
}
proc pr_node[T] (d:int, x:aNode[T]) {
print$ " " * d;
print$ f"B(%d)\n" (x.index);
}
proc pr_treeT[T](tree:avl[aNode[T]]) {
Avl::iter[aNode[T]] ((pr_node of (int*aNode[T])), tree);
}
proc pr_node (d:int, x:aNode[int]) {
print$ " " * d;
print$ f"B(%d.%d)\n" (x.index, x.element);
}
proc pr_node (d:int, x:aNode[double]) {
print$ " " * d;
print$ f"B(%d=%.1f)\n" (x.index, x.element);
}
//proc pr_treeD[double](tree:avl[aNode[double]]) {
proc pr_treeD(tree:avl[aNode[double]]) {
Avl::iter[aNode[double]] (pr_node of (int*aNode[double]), tree);
}
fun main () =
{
var ar <- new vArray[double](0.0);
adder(ar, 4, 88.1);
adder(ar, 5, 23.1);
adder(ar, 1, 53.1);
pr_treeD(ar.arr);
endl;
return 0;
}
System::exit (main());
-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Felix-language mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/felix-language