On Sep 3, 2006, at 4:53 AM, skaller wrote: > On Sun, 2006-09-03 at 09:49 +1000, skaller wrote: > > Yup, fixed: typematch works.
After updating and building felix, your example works on OS X ppc, too :) > The *problem* is that the reduction code is eagerly reducing > everything. > I just reduce left right and centre: the code assumes confluence. I looked at Barry Jay's paper carefully and though I agree the matchable forms constraint seems necessary to catch errors in the forms, if you assume the forms are correct then the variables are bound symmetrically "in both the pattern and the body," p 4. This idea of pattern binding also came up (convergent evolution--great minds think alike) in "Scrap Your Boilerplate Revolutions" (2006), at http://www.informatik.uni-bonn.de/~loeh/SYB1.html . > so the only difference is that in my form an explicit pattern > is parsed and used to identify the variables, and the shape > of this pattern acts as a limitation: Jay removes that limitation. Thanks for the great overview! I really appreciate the help. Of course, there a few things I may return: First, let me describe the problem (partly in Felix) this system is trying to overcome: ------------------------ open List; union Company = C of list[Dept]; union Dept = D of Name * Manager * list[SubUnit]; union SubUnit = | PU of Employee | DU of Dept ; union Employee = E of Person * Salary ; union Person = P of Name * Email ; union Salary = S of int; typedef Manager = Employee; typedef Name = string; typedef Email = string; // this mess is due largely to List val flxPty:Company = C (Cons ((D ("R&D", skaller, (Cons ((PU tryzelaar), Cons ((PU percossi), Cons ((PU tanski), Empty[SubUnit]) ))))), Empty[Dept])); var skaller:Manager = E (P ("John Skaller", "email hidden"), S 100000); var tryzelaar:Employee = E (P ("Erick Tryzelaar", "email hidden"), S 80000); var percossi:Employee = E (P ("Martin Percossi", "email hidden"), S 80000); var tanski:Employee = E (P ("Peter Tanski", "email hidden"), S 35000); --------------------- (This example is a felix version of the example in the early generic- programming paper "Scrap Your Boilerplate--Generic Programming" (2003), available at http://www.cs.vu.nl/ boilerplate/ .) The problem here is that to work with this type-safe database you would have to write a separate function for each match of Company, Dept, SubUnit, Employee, Person, and Salary. Each function would be similar to: fun incrEmpSalary : int -> Employee -> Employee | n (_,?s) => incrSalary n s | n _ => ; fun incrSalary : int -> Salary -> Salary | n (S ?s) => n + s | n _ => ; To get over this problem (in a congruent type-safe way), you need a function that can operate over a general data type based on its form. The problem with the implementation as I attempted to test it was the constructors in unions. When I tried this (just to test the syntax better): --------------------- typedef typecase[clst] C clst => clst endcase a1 = company; typedef typecase[dp,n,m,sb_lst] D (n,m,sb_lst) => mgr m * (map sbu sb_lst) endcase a2 = dpt; typedef typecase[e] P e => e endcase a3 = sbu; typedef typecase[p,s] E (p,s) => (p,s) endcase a4 emp; --------------------- I get an "unknown" parser error. I get the same unknown error if I attempt to create symbols for the constructors: --------------------- typedef typecase[co,clst] co clst => clst endcase a1 = company; --------------------- This last *is* the intended form for the generic type (compare with the Point example at the beginning of Barry Jay's paper. Anyway, if it is possible to use this last (intended) form for the generic type, we could write a typecase for a union of a certain form, such as a single-constructor union: --------------------- typecase[c,a] c a => a endcase a1; --------------------- Or we could make a generic traversal function, as you did in your example. Do you think that's possible? -Pete ------------------------------------------------------------------------- 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
