Through my usual compiler hackery, this example now seems to work:
///////////////////////////////
#import <flx.flxh>
typeclass X[t] {
virtual fun addx: t * t -> t;
}
instance[u with Integer[u]] X[u*u] {
fun addx: (u*u)*(u*u) -> u * u=
| (?a,?b),(?c,?d)=> (a+c,b+d);
;
}
open[v] X[v*v];
val i=1;
val j=2;
val k=3;
val l=4;
var m:int;
var n:int;
(m,n) = addx$ (i,j),(k,l);
print$ f"%d,%d\n"$ m,n;
///////////////////////////////
The key thing here is that the open directive now supports opening
a schema, in other words, a partial specialisation.
Now consider this tutorial example:
/////////////////////////////////////
#import <flx.flxh>
include "stl";
open Stl;
open Stl::Vector;
open Stl::Map;
open[k,v] Bidirectional_iterator[Stl::Map::stl_map_iterator[k,v],k*v];
typedef ii = Vector::iterator[int];
var v = Vector::create[int]();
push_back (v,1);
push_back (v,2);
push_back (v,3);
var j = 0; until j==3 do
print v.[j]; endl;
++j;
done;
var m = Map::create[int,int]();
insert(m,0,2);
insert(m,1,23);
insert(m,2,423);
j = 0; until j==3 do
print m.[j]; endl;
++j;
done;
var i = begin m; until i == end m do
def val k, val vl = deref i;
print k; print " -> "; print vl; endl; ++i;
done;
//////////////////////////////////////
you see we now can 'open' the STL map iterator
for all key,value types.
That line used to say:
open Bidirectional_iterator[
Stl::Map::stl_map_iterator[int,int],
int*int
];
In other words, previously you had to specify
the full type of the iterator. Now, we can open
it 'polymorphically' .. which means we can
open it in the library.
--
John Skaller <skaller at users dot sf dot net>
Felix, successor to C++: http://felix.sf.net
-------------------------------------------------------------------------
SF.net email is sponsored by: A Better Job is Waiting for You - Find it Now.
Check out Slashdot's new job board. Browse through tons of technical jobs
posted by companies looking to hire people just like you.
http://jobs.slashdot.org/
_______________________________________________
Felix-language mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/felix-language