On 23/09/2014, at 8:23 AM, john skaller wrote:

> The new compiler organisation is based on early monomorphisation.

Always some fun problem. 

To monomorphise stuff, for Felix things we just replace
the type variables with concrete types.

But what about a primitive, eg a function?
To monomorphise a primitive function we'd have to replace
the ?1 ?2 etc in the string of C++ code with the C++ type:
this is done in the back end. It shouldn't (and more or less
cannot) be done in the front end.

So I decided to just leave primitives polymorphic.

So for example with

        type vector[T] = "vector<?1>";

we just keep it. So consider:

        fun begin[T]: vector<T> -> cptr[T] = "$1.begin()";

Now vector[T] is a fine argument. It's a primitive so
we have a polymorphic type. 

however assume cptr is defined by

        union cptr[T] =  Null | Ptr of T

that's a felix type, and cptr doesn't exist after monomorphisation,
instead we have, for example

        union cptr_int = Null | Ptr of int
        union cptr_float = Null | Ptr of float

Now actually, we could leave ALL (nominal) types polymorphic.
That would fix the above problem. However it isn't clear
what happens with closure formation: it would still work
with the existing code, but teh whole idea of complete
monomorphisation was to get rid of all the code handling
polymorphism in the optimisation and back end.

There is a solution:

        fun begin_int[T where T=int] : vector<int> -> cptr_int = ....

In other words, make separate copies of the function
for every instance of T, but leave the type variable T in
all these definitions. It isn't used in the signature but
it has to be saved to indicate the C++ code in the
definition may need substitution later.

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




------------------------------------------------------------------------------
Meet PCI DSS 3.0 Compliance Requirements with EventLog Analyzer
Achieve PCI DSS 3.0 Compliant Status with Out-of-the-box PCI DSS Reports
Are you Audit-Ready for PCI DSS 3.0 Compliance? Download White paper
Comply to PCI DSS 3.0 Requirement 10 and 11.5 with EventLog Analyzer
http://pubads.g.doubleclick.net/gampad/clk?id=154622311&iu=/4140/ostg.clktrk
_______________________________________________
Felix-language mailing list
Felix-language@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/felix-language

Reply via email to