I have hacked at the compiler so it now supports this program:

///////////////////////////////////////////
#import <flx.flxh>

typedef fun pair (t:TYPE):TYPE => t * t;
typedef Pair[t] = t * t;

var x: pair int;

fun f[t,u:TYPE->TYPE] (x: u t)=>x;

var k = f[int, the pair] (1,2);
//var k = f[int, Pair] (1);

print k.(0); print ","; print k.(1); endl;
///////////////////////////////////////////

The thing to note here is that 'the pair' which has
metatype TYPE->TYPE can be passed as an explicit type
argument to function f. The application

   u t

is actually resolved now in the call:

   f[int, the pair] (1,2)

for which the assignments

   t -> int
   u -> the pair

resolves to

   (the pair) int

and thence to

  int * int

In effect, 'the pair' is a type function CLOSURE, which can be
passed 'by value' and bound to a type variable of the right kind.

[Note: the representation of typedef fun .. has always been
of an alias for a lambda expression, that is, a closure.
However for Pair above, we will need to eta-expand it like:

   typedef _pair (x:TYPE):TYPE => Pair[x];

since the representation of Pair in the compiler is:

        `BTYP_inst (index, ts)

which is a closed form: the ts have to be given. We actually
want the type function:

        lambda ts. `BTYP_inst (index, ts)

that is, with a 'hole' where the ts have to go, which we can
do in the usual way of opening closed forms using 
lambda abstraction]


In other words .. we have 'first class functors' in the compiler
in at least one context (but not at run time of course).

Our ACTUAL purpose here is still some way off: we need to
do what Haskell can do with typeclasses: allow variables which
bind to type *constructors* (functors), not just types.
For example:

        typeclass X[container, valuetype] {
                virtual fun getone: container[valuetype] -> valuetype;
        }

would be nice. In particular

        instance X[vector, int] {
                fun getone: vector[int] -> int = "*($1.begin())";
        }

would be an instance. The idea here of course is actually:

        typedef containers = typesetof(vector,list, deque);
        instance[c:containers,t] X[c,t] { ...


which instantiates all the X like containers in one line.

Of course .. C++ can already do this in a crude manner by passing
a class template to a template as an argument.

The main problem here is typeclasses cannot currently accept
arguments other than of kind TYPE .. any kinding annotation
is simply dropped, and when a kind is needed it is just
set to 'TYPE' .. typeclasses would never have been got working
if I'd had to deal with kinding AS WELL as other things.


-- 
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

Reply via email to