On 04/09/2012, at 1:39 PM, john skaller wrote: > > On 04/09/2012, at 11:38 AM, john skaller wrote: > >> Last night i said to Shayne: "Felix needs more magic" > > ftp://ftp.cpsc.ucalgary.ca/pub/projects/charity/literature/manuals/manual.ps
So for a union like union X [A,B] = | X1 of A | X2 of A * B | X3 of A+B ) ... map is clearly: fun map[A,B, A', B'] (fa: A -> A') (fb: B -> B') (x:X[A,B]) : X[A',B'] = { match x with | X1 ?a => X1 (fa a) | X2 (?a,?b) => X2 (fa a, fb b) | X3 (?k) => match k with | case 0 ?a => case 0 (fa a) | case 1 ?b => case 1 (fb b) In more compact form, A * B can be handled itself by a (trivial) map, as can A+B. If we run into an X[A,B] valued subterm, we just reapply the map. This machinery cannot handle exponentials, i.e. functions, i.e. terms of type A -> B etc. Given some k: A -> B we can compose it: inmap . k . outmap where inmap: A' -> A, outmap B -> B' We can take outmap as fb, but inmap would have to be the inverse of fa. In general then, we have to provide, for each type variable, a pair of functions which are inverses. Note this also applies to arrays (since they're exponentials). If run into a term of type X[ h (A,B), j (A,B) ] where h or j is not the first or second projection, we have polymorphic recursion, and we have to construct new fa, fb maps for h and j. Ouch! Fold is similar. For one type variable it's trivial, it's just a simple visitor. -- 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