On 07/11/2010, at 6:40 PM, john skaller wrote: This kind of type munging:
> > type _comparator[CT,FT2,FFT] = "comparator<?1,?2,?3>"; > typedef comparator[T] = _comparator[T,T*T,T*T->bool]; > > fun _make_comparator[CT,FT2,FFT]: FFT -> comparator[CT] = > "comparator<?1,?2,?3>($1)"; > fun make_comparator[T](cmp:T * T -> bool) => _make_comparator[T, T*T, > T*T->bool] (cmp); is a big problem in Felix. The issue is: we don't know the C type names for Felix types like int * int // tuple of two ints This also makes "separate compilation" including building usable libraries almost impossible: you can do it by being very careful to only use C types, C functions, etc. Some readers may wonder why Felix doesn't use things like pair<T1, T2> as the C++ name for Felix's T1 * T2, since they're isomorphic and layout compatible,and that would provide a canonical name, instead of what Felix actually uses, a name like _x76534_something_weird_77dxgj The answer to this question is: C++ templates with C++ syntax fails to preserve an important property C structs have which is fundamental and vital for Felix: support for type recursion. In C you use a pointer to an incomplete type to get type recursion. Pointers are fine in structs because direct recursion would lead to an infinite expansion unless you had conditional typing (which Felix actually does have!). Unfortunately you can't reliably do this with template names. For example a list is given by: typedef list<T> = pair<T, *list<T> >; in C++, and this is even worse: typedef list<T> = pair<T, pointer<list<t> > >; This is a real pity. We don't actually want the template definitions, we'd just like the templates to allow systematic naming of types (we'd use specialisations for the actual definitions). The fact the name is not in scope is only the first problem, the second is that there are no templated typedefs. If you hack it with classes: template<class T> struct X { typedef T type; }; you get into a real mess: given some type W, is that W or W.type you should be using? Or W<int> or W<int>.type ...? This is not mere confusion (the compiler would not be confused), the problem is that the extra boundary destroys orthogonality: X is parametric, but it isn't the type we want. But for STL vector, it IS the type we want. Anyhow, that's the problem: templates interfere with type recursion. -- john skaller skal...@users.sourceforge.net ------------------------------------------------------------------------------ The Next 800 Companies to Lead America's Growth: New Video Whitepaper David G. Thomson, author of the best-selling book "Blueprint to a Billion" shares his insights and actions to help propel your business during the next growth cycle. Listen Now! http://p.sf.net/sfu/SAP-dev2dev _______________________________________________ Felix-language mailing list Felix-language@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/felix-language