This code now works:
//////////////////////////////////////////
#import <flx.flxh>
typedef fun pair (t:TYPE):TYPE => t * t;
typedef Pair[t] = t * t;
typedef PAIR = fun (t:TYPE):TYPE =>Pair[t];
var x: pair int;
fun f[t,u:TYPE->TYPE] (x: u t)=>x;
var k1 = f[int, the pair] (1,1);
var k2 = f[int, (fun (t:TYPE):TYPE =>Pair[t] ) ] (1,2);
var k3 = f[int, the PAIR] (1,3);
var k4 = f[int, the Pair] (1,3);
print k1.(0); print ","; print k1.(1); endl;
print k2.(0); print ","; print k2.(1); endl;
print k3.(0); print ","; print k3.(1); endl;
print k4.(0); print ","; print k4.(1); endl;
/////////////////////////////////////////////////
Note in particular you can say 'the Pair' to convert
the parameterised type Pair into a type function
with the parameters are type arguments (i.e. a functor).
I think this will only work when the arguments and
return type have kind TYPE, i.e. you can't accept or
return a functor.
This upgrade to the polymorphism should allow things like:
gen singleton[t,c:TYPE->TYPE]: t -> c = "?2($1)";
var x = singleton[int, the stl_vector] (1);
var y = singleton[int, the stl_list] (1);
assuming that stl_vector and stl_list are functors representing
STL containers with constructors that take a 1 element argument.
But I haven't tested it yet .. :)
More generally we'd like to create a single instance of typeclass
XSequence which takes the C++ data functor as an argument.
At present sequence takes 3 arguments
typeclass Sequence [container, iterator, value] ..
where both container and iterator have to be instantiated over
value. EG
instance Sequence [vector[int], vector_iterator[int], int]
This prevents abstraction over the value type, since the first
argument, for example, has to be a type such as 'vector[int]'.
We'd rather have
instance Xsequence[vector, vector_iterator, int]
because we can abstract now:
instance[t] Xsequence[vector, vector_iterator, t]
and again:
instance[t, c:TYPE->TYPE, it:TYPE->TYPE]
Xsequence[c,it,t]
We could do this with Sequence like:
.. Sequence[c t, it t,t]
now, since we can pass functors like 'c' and 'it' directly.
Well actually this is only implemented for functions and
not typeclasses, but the method is established... :)
Haskell typeclasses can do this, and, it is essential for
the Monad typeclass required for monadic programming ..
so we do need this.
--
John Skaller <skaller at users dot sf dot net>
Felix, successor to C++: http://felix.sf.net
-------------------------------------------------------------------------
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