I'm looking at reductions in light of the GHC techniques described in this paper:
http://research.microsoft.com/~simonpj/Papers/rules.htm and as part of that I'm looking at the foldr/build model of lists, and implemented this for starters: be scared to look at the generated C++ .. but it does work, amazingly: /////////////////////////////////////////////////// #import <flx.flxh> // Play with foldr/build list construction open List; instance[T with Show[T]] Str[List::list[T]] { fun str (xs:List::list[T]) => '[' + match xs with | Empty[T] => '' | Cons(?o, ?os) => List::fold_left ( fun (a:string) (b:T):string => a + ', ' + (repr b) ) (repr o) os endmatch + ']' ; } // Felix uses this form of foldr: // fun fold_right[T,U] (_f:T->U->U) (x:list[T]) (init:U):U = // where the function is first, the list second, and the initial // value to be folded into is last, so Haskell's // foldr f x l in Felix is fold_right f l x fun down1 (cons:int * list[int] -> list[int]) (nil: 1 -> list[int]) (n:int) => if n == 0 then nil() else cons (n, down1 cons nil (n-1)) endif ; fun nil[t] () => Empty[t]; fun cons[t] (x:t,xs:list[t])=> Cons (x,xs); val x = down1 the cons[int] the nil[int] 4; print$ str x; endl; fun build[t,u] (g: (t * list[t] -> list[t]) -> (1->list[t]) -> u -> list[t]) (x:u) => g the cons[t] the nil[t] x ; val x2 = build[int,int] the down1 6; print$ str x; endl; /////////////////////////////////////////////////// -- John Skaller <skaller at users dot sf dot net> Felix, successor to C++: http://felix.sf.net ------------------------------------------------------------------------- Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys-and earn cash http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV _______________________________________________ Felix-language mailing list Felix-language@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/felix-language