On 04/08/2012, at 2:46 PM, john skaller wrote: > > On 04/08/2012, at 11:36 AM, john skaller wrote: > >> I am implementing new instantiation rules and have run into a >> nasty bug. > > > This is the case that caused the problems: > > class S_expr > { > union sexpr[T] = | Leaf of T | Tree of list[sexpr[T]]; > > instance[T with Str[T]] Str[sexpr[T]] { > fun str(x:sexpr[T])=> > match x with > | Leaf ?a => str a > | Tree ?b => str b > ; > } > } >
Removing S_expr from the library I now have everything building and working including rank! This now prints 5 like it should: ////////////// class Trick[T] { virtual fun rank : 1 -> int; } instance [A,B] Trick[A -> B] { fun rank() => 1 + Trick[B]::rank (); } instance [K] Trick [K] { fun rank() => 1; } typedef int5 = int -> int -> int -> int->int; println$ Trick[int5]::rank(); ////////////////// This is similar to recursive reduction in C++ templates, where typically one uses an int, subtracts one in the general case when recursing, and provides a ground case with the int = 0 to stop the recursion. Felix doesn't allow ints as "type variables" like C++ does. So using a type like int5 above is a trick to overcome this until we can provide the proper mechanism. It may seem we can do this with unitsum types, if we could subtract 1 from them, I may look at that. However the "right" way to do this requires introducing a proper kinding system and allowing "type variables" to be values of any kind, not just the kind TYPE. This has other uses, as mentioned type matches are currently used for predicates on type: T in typesetof (int, double) means typematch T with | int => 1 | double => 1 | _ => 0 endmatch however the result is a type, either 0 or 1 which stand in for FALSE or TRUE which are types, i.e. values of kind TYPE. They should not be -- you'd not want to use the result as an actual type anywhere! As with C not having a bool type, values of 0 and 1 standing in for a real bool type, so 0 and 1 as types stand in for a real BOOL kind. -- 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