On Sat, 2006-09-02 at 19:58 -0400, Peter Tanski wrote:
> On Sep 2, 2006, at 2:01 PM, skaller wrote:

> Ah. So in pattern calculus a Tuple will be defined similar to a List:

You're missing the point here.  The tuple constructor term is
*already* a list:

        `BEXPR_tuple (es)    // expressions
        `BTYP_tuple (ts)     // types

There is no problem to write a fold or map over the argument
of a tuple constructor in Ocaml .. I mean it's just
List.fold etc.

There is also no real problem 'exporting' such a map
or fold into Felix.

The problem is writing the *argument* function of map or fold.
It has to be an Ocaml function .. but the client can
only write a Felix one.

So the Felix one must translate into an Ocaml one.

In general this is done by considering some Felix
term, as represented in Ocaml, 'as a function',
that is, by writing what amounts to an interpreter
routine.

For example there is a routine to handle

        typematch t with
        | ?x * ?y * ?z => f x * f y * f z
        | ?x * ?y => f x * f y 
        | _ => t
        endmatch

which can take some type t, and if it is the type of a tuple
of 2 or 3 elements, return a new type of the same length,
for which the component types are mapped by the type function
(functor) f.

The problem here is that the patterns must be constants.

This problem could be solved if, for example, I allowed:

        ?h ** ?t

as a pattern, where the intent is to match a tuple, but
return only the head element and a tail tuple.
Then the corresponding constructor on the RHS would
allow recursion to be used to process the whole
list of elements.

This is precisely how the user defined syntax parser
(pattern matcher) and macro processor (substitution
constructor) work together to actually allow this
at the Abstract Syntax Tree level.

So the *actual* problem is to somehow allow treating
a tuple type as a list in typematching, and similarly,
allow iterative construction of a tuple.

However this is just one problem, specialised to tuples.
A similar thing would be needed for unions, records, sums,
and all other constructors taking a list of arguments .. 
and then there are even more complex ones like GLR grammar stuff.

With the pattern calculus, the 'data constructor': tuple,
sum, union, whatever .. no longer has to be a constant.
So I only have to do this hackery ONCE for each HOF,
and ONCE for each constructor, the pattern calculus
can substitute in the requisite constructor: ordinary
pattern matching cannot, because the patterns have
to be constants.

That is my hope: pattern calculus allows *real* generic
programming because the data functors can be variables too.

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


-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Felix-language mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/felix-language

Reply via email to