One of the major problem facing Felix is the lack
of a canonical name for its types. It's ok to require a user
to export a function or procedure. However exporting
types is horrible and it doesn't really work.

The problem is partly avoided by C functions with used defined
names because C linkage does not provide type safe linkage.
But that also introduces a problem!

Consider this function:

        fun sum(x:list[int]) => fold_left + of (int*int) 0 x;

We'd like to just say:

        export fun sum(x:list[int]) => fold_left + of (int*int) 0 x;

and export it as C++. We have to use C++ linkage because there could
be many functions called sum. We would also like to gain the benefits
of type safe linkage.

The problem here is: what is the C++ name of the type list[int]?

The current answer is something like:

        _tt936478

in one compilation and for another file

        _tt223456

Felix just uses a fresh integer whenever it needs to invent the name of a 
an anonymous/structural type (such as a list).

Now a list is defined (in effect) by:

        (1 + T * self) as self

which means "empty or T and list". It is easy to name tuples:

        tup2<int, long>

would suffice. Similarly variants:

        var2<double, string>

and there's a way to synthesise names for unions based variants (since the 
union and the
components all have names, at least unique in their scope). But how to do the
recursion?

Here's the answer, this actually works on g++:

    // core combinators
    struct unit;
    struct point;
    template<class T,class U> struct fix;
    template<class T, class U> struct tup2;
    template<class T, class U> struct var2;

    template <> struct   
      fix<
        point,
        var2<unit, tup2<int,point> > 
      > 
    { 
      // definition goes here
    };


using the fix and point types to represent recursion. 

--
john skaller
skal...@users.sourceforge.net
http://felix-lang.org




------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Felix-language mailing list
Felix-language@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/felix-language

Reply via email to