Hi,
I sort of understand, but still puzzled. In the following code, because
the member function is generic, the parameters are generic, and are
resolved when it's called. I was thinking I should be able to have a non
generic "eq(itm, head)" but I'm required to have a generic version of
eq, even though the function is only called with T is int, and there
exists an eq:int*int->bool so it should be ok. So that means the
arguements aren't generic when it's being type checked, in fact they're
very specific, being of the type "generic", so if they're passed to a
function, felix has to be able to find a version of the function with
the specific "generic" type arguments ...
Oh. Compile time ... how did I get virtual functions in that box?!
So that's why generic functions never really do anything, all the "work"
is done by a function that's passed in with a signature appropriate to
the context ...
I should probably just trash this message, but I guess some people will
find it amusing! : )
cheers,
Jonathan.
//------------
#import <flx.flxh>;
open List;
fun eq[T] : T * T -> bool = "$1==$2";
fun member[T] (itm:T) (lst:list[T]) : bool =
{
return
match lst with
| Empty[T] => false
| Cons[T] (?head, ?tail) =>
if eq[T](itm, head) then
true
else
member itm tail
endif
endmatch;
}
var x1 = 1;
var x2 = 2;
var x3 = 3;
var x4 = 4;
var ilst = Cons( x1, Cons( x2, Cons( x3, Cons( x4, Empty[ int]))));
print (member (x3) ilst);
endl;
//------------
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Felix-language mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/felix-language