On Thu, 2007-04-26 at 17:51 -0400, Chris King wrote:

> Now I don't know enough about C++ to judge how much of the template
> system's functionality the typical C++ programmer uses, but I'd guess
> most programmers use it for nothing more than polymorphic type safety
> and could transition to Felix's type system without needing to be
> convinced of its benefits: in their eyes the systems are "equivalent".

Yes, that is almost but not quite true. 

* Felix polymorphism is currently only first order.

* Parametric polymorphism *disallows* phase-2 lookup

* C++ can't do type recursion so you can't 
  do combinatorial stuff

By two-phase lookup I mean you can NOT do this in Felix:

fun f[t](x:t)=> x + x;

C++ allows this however, provided operator + is in scope
at the point of instantiation. This is clearly incoherent
and should never have been permitted.

To 'fix' this problem, C++ has Koenig Lookup (my name,
after inventor Andrew Koenig, now called DNL = Dependent
Name Lookup).

This causes the lookup to search in the scope of the 
template argument definition, and thus reduces the
incoherence which could come from binding to different
functions in different use contexts.

In particular, this provides good protection for classes,
where lookup of 'method' names in syntax like:

        T x; x.f();

will usually find to the same f, independent of context.
But of course it depends on T. So somehow this 'packages'
the methods of a class with the class name, turning them
into a kind of module, and making templates more likely
to meet the parametricity requirement, that is, to be
functors/natural transforms.

Where 'ad hoc' polymorphism is required here, Felix 
uses the Haskell typeclass technique: the polymorphism
is no longer parametric, but it is modelled and type checked
as such: obeying the semantic obligations, however, is
up to the user when coding the instances.

Typeclass instances are actually equivalent to C++ template
(partial) specialisations.

Because of the 'macro' expansion nature of templates, they
can actually do higher order polymorphism AND you can actually
do generic = functorially polymorphic = polyadic programming
impossible in Ocaml, and more or less impossible in Haskell.

However that level of 'generics' or 'meta-programming' is quite
unsound in C++ .. it 'sort of works' enough of the time to make
C++ programmers think it is cool. The power provided IS cool!
The restrictions and unsoundness definitely aren't!

-- 
John Skaller <skaller at users dot sf dot net>
Felix, successor to C++: http://felix.sf.net

-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Felix-language mailing list
Felix-language@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/felix-language

Reply via email to