More fun: var x1 : typematch int * long * string with | ?h ** ?t => t endmatch = 2L, "Hello"; println$ x1;
typedef fun tail (T: TYPE) : TYPE => typematch T with | ?h ** ?t => t endmatch; var x2 : tail (int * long * string) = x1; println$ x2; var x3 : tail (tail (int * long * string)) = "hey"; println$ x3; typedef fun succ (T:TYPE) : TYPE => typematch T with | 0 => 1 | 1 => 2 | 2 => 3 | 3 => 4 | 4 => 5 | 5 => 5 endmatch ; typedef fun tlen (T:TYPE):TYPE => typematch T with | ?h ** ?t => succ (tlen t) | _ => 1 endmatch ; var x4 : tlen (int * long) = true; println$ x4; Note: this stuff is only working for types at the moment, so we use the trick of making a variable of the type and printing it as a way to check the right type is calculated. We have to *do* something with the variable to stop it being elided, and assigning a value of a known type checks that the operation is working (if not we get a type error). The "succ" function is a hack, when we have "sum_cons" as well as tuple_cons that will go away too. BTW: the way this is used to "str" a tuple, for example, is to define str on tuples on H ** T as str H + ", " + str T. This will invoke the usual instance of str for any type H, and do reductive polymorphic recursion of the tail T (i.e. call itself with the tail of the tuple). This is what Dobes is asking about: how do we "str" a tuple? The answer is, we have to use a polymorphic function which handles ANY component type: just the same as it is done now in lib/std/tuple.flx. The difference is we only do this for the head of the tuple and then call virtual str on the tail which dispatches to the same tuple handling instance that just called it with polymorphic recursion (i.e. the call is NOT recursive because the type is different). Its the same as in C++, unrolling be repeatedly applying a template until we reach a ground case. The result is exactly the same as writing out str x.0 + "," + str x.1 + "," + str x.2 ",." + ... -- 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