On Mon, 2006-09-11 at 23:35 -0400, Peter Tanski wrote:
> On Sep 11, 2006, at 9:34 PM, skaller wrote:
> There are two problems, aside from those you mentioned:
Is that all? :-)
> (1) the typeclass should redirect to the typeclass instantiation
> _for_that_type_. In your example:
>
> > typeclass X[u,v] { fun add: u * v -> u; }
> > fun f[s,t where X[s,t]] (x:s,y:t) { .. add(x,y) .. }
>
> somewhere there should have been an instance of typeclass X:
>
> instance X[s,t] {
> fun add: s * t -> u;
> }
No. The instance will be something like:
instance X[int,long] { fun add: int * long -> int = .. }
The inner binding of the function f doesn't need to know about it
and cannot. It's the same as binding against an abstract class
with pure virtual methods: the actual dispatch is delayed.
We might call:
fun g[a,b] (x:a, y:b) { return f[a,b] (x,y); }
g[int, long](1,2);
so that the instance X[int,long] flows down the call chain,
but Felix does not bind this way. It binds everything
fully polymorphically, and instantiates later.
In other words, when binding the instructions of f,
we know nothing of the actually types which WILL later
be substituted for the type variables .. in fact
we can't, because f can be called from multiple
places with different type arguments.
As a note, the full polymorphism is carried to the
extreme. The instantiation is never physically done
to Felix code. The C++ code generator is responsible
for generating instances given a polymorphic entity
and a binding of the type variables to ground types.
The instantiator builds this substitution, but it
never applies it. Thus, the front end can support
intensional polymorphism, eg we could just generate
C++ templates, if only they allowed type recursion
(which they don't).
> > What we ACTUALLY need to do is: specialise the typeclass
> > based on the types supplied in the function in the
> > where clause,
> This specialisation should be done only in the user-defined instance
> declaration for the typeclass.
No, see above, that will not work.
> > The problem here is exactly equivalent to this:
> >
> > open X[s,t];
> >
> > were X a module: we want to open an *instance* of X
> > for lookup, for which u,v are replaced by the arguments s,t.
>
> It is the replacement that is a problem.
Yes, that is the problem: there's no way to do it with
the existing data structures, but it has to be done.
--
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