I'm trying to figure out how to make libraries with Felix.
Roughly speaking you can do this now by:

1. Make some code, and export some types and functions.

This gives the functions dlopen() names (bypassing
C++ typesafe linkage).

The type names are specified are provided as typedefs.
This means they're just aliases for weird Felix mangled names.

Example flib.flx:

fun f(x:int, y:int)=>x + y;
export int as "myint";
export int * int as "myint2";
export fun f of (int * int) as "myf";


2. Write a Felix wrapper for the library, just as
if it were a C library:

type myint = "myint";
type myint2 = "myint2";
fun f: myint2 -> myint = "myf($1)";

Note myint and myint2 are abstract types. You can't
construct myint2, nor can you get one of its components.

In this case, you can also do this:

fun f: int * int -> int = "(int)myf(reinterpret<#t>($1))";

Reinterpret<> is a Felix C++ library template that can do
reinterpret casts on rvalues. #t is the code for "the type
of the argument tuple"

Now, it should be simple enough to make a 'library' declaration
which causes Felix to emit say

        flib.flxi

which is the above Felix wrapper, except that there is a problem
with types. Every Felix compilation will name the same algebraic
type differently, including primitives (abstract types) such
as 'int'  (actually, int,long etc are special cases and retain
their C names .. but it is a hack for making some code look
cleaner and can't be relied on).

THE PROBLEM is that C++ is a very bad language and templates
do not work the same way as non-template code when it
comes to types: recursive template classes can't be defined.

Ideally, we use the names

template<class T, class U> struct tuple2<T,U>;
template<class T, class Y> struct function<T,U>;
// etc

as canonical type names. Felix would then simply
specialise them, instead of using a synthesised name.

Unfortunately, it isn't possible to do that if the
type is recursive, for example:

        typedef function<int,f_t> f_t; // C++ typedef

doesn't work. This is a function type:

        typedef r = int -> b as b; // Felix typedef

of which this:

        fun f(x:int):r = { println "hi"; return the f; }

is an example (yes, it works fine). The same problem
applies to tuples, unions, etc.


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

-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >>  http://get.splunk.com/
_______________________________________________
Felix-language mailing list
Felix-language@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/felix-language

Reply via email to