Revisions
-
killerswan revised this gist
Apr 26, 2011 . 1 changed file with 12 additions and 4 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,3 @@ (* This uses the @ operator (aka List.append) which is not tail recursive *) let suffixes list = let rec loop l acc = @@ -7,6 +6,7 @@ let suffixes list = | x::xs -> loop xs (acc @ [xs]) in loop list [list] (* This uses an operator @+ constructed from two tail recursive methods... :P *) let suffixesTR list = let (@+) x y = List.rev_append (List.rev x) y in @@ -16,6 +16,7 @@ let suffixesTR list = | x::xs -> loop xs (acc @+ [xs]) in loop list [list] (* These can be rewritten from scratch... *) let myrev list = let rec loop acc list1 = @@ -33,6 +34,7 @@ let myappend lis t = (*...*) (* Or even more condensed *) let rec myrevappend acc list = (* note that this is different from the builtin *) match list with @@ -50,9 +52,8 @@ let suffixesTR1 list = | x::xs -> loop xs (acc @++ [xs]) in loop list [list] (* Adding a left fold to the mix... *) let suffixesTR2 list = let (@+++) li st = let xcons acc x = x::acc in @@ -64,4 +65,11 @@ let suffixesTR2 list = | [] -> acc | x::xs -> loop xs (acc @+++ [xs]) in loop list [list] (* Nice to play with all that, but Brian McNamara's, where we started, has got to be faster: https://gist.github.com/941867 Every version I've shown here does a bunch of repetitive list reversing. *) -
killerswan revised this gist
Apr 26, 2011 . 1 changed file with 8 additions and 12 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,6 +1,4 @@ (* This uses the @ operator (aka List.append) which is not tail recursive *) let suffixes list = let rec loop l acc = @@ -52,20 +50,18 @@ let suffixesTR1 list = | x::xs -> loop xs (acc @++ [xs]) in loop list [list] (* This isn't really that much better than what we started with, of course. :D Adding a left fold to the mix... *) let suffixesTR2 list = let (@+++) li st = let xcons acc x = x::acc in let fc = List.fold_left xcons in fc st (fc [] li) in let rec loop l acc = match l with | [] -> acc | x::xs -> loop xs (acc @+++ [xs]) in loop list [list] -
killerswan revised this gist
Apr 26, 2011 . 1 changed file with 3 additions and 5 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,8 +1,6 @@ (* This uses the @ operator (aka List.append) which is not tail recursive *) let suffixes list = let rec loop l acc = @@ -38,7 +36,7 @@ let myappend lis t = (*...*) (* Or even more condensed *) let rec myrevappend acc list = (* note that this is different from the builtin *) match list with | [] -> acc | x::xs -> myrevappend (x::acc) xs @@ -61,8 +59,8 @@ let suffixesTR1 list = let suffixesTR2 list = let (@+++) li st = let prepend acc x = x::acc in let lfc = (List.fold_left prepend) in lfc st (lfc [] li) in let rec loop acc l = -
killerswan revised this gist
Apr 26, 2011 . 1 changed file with 27 additions and 22 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,19 +1,24 @@ (* This uses the @ operator (aka List.append) which is not tail recursive *) let suffixes list = let rec loop l acc = match l with | [] -> acc | x::xs -> loop xs (acc @ [xs]) in loop list [list] (* This uses an operator @+ constructed from two tail recursive methods... :P *) let suffixesTR list = let (@+) x y = List.rev_append (List.rev x) y in let rec loop l acc = match l with | [] -> acc | x::xs -> loop xs (acc @+ [xs]) in loop list [list] (* These can be rewritten from scratch... *) let myrev list = @@ -42,15 +47,16 @@ let myappend1 lis t = myrevappend t (myrevappend [] lis) let suffixesTR1 list = let (@++) = myappend1 in let rec loop l acc = match l with | [] -> acc | x::xs -> loop xs (acc @++ [xs]) in loop list [list] (* This isn't really that much better than what we started with, of course. :D *) (* Adding a left fold to the mix... *) let suffixesTR2 list = @@ -59,10 +65,9 @@ let suffixesTR2 list = let lfc = (List.fold_left xcons) in lfc st (lfc [] li) in let rec loop acc l = match l with | [] -> acc | x::xs -> loop (acc @+++ [xs]) xs in loop [list] list -
killerswan revised this gist
Apr 26, 2011 . 1 changed file with 15 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -51,3 +51,18 @@ let suffixesTR1 list = (* This isn't really that much better than what we started with, of course. :D *) (* Adding a left fold to the mix... *) let suffixesTR2 list = let (@+++) li st = let xcons xs x = x::xs in (* okay... *) let lfc = (List.fold_left xcons) in lfc st (lfc [] li) in let rec loop acc l = match l with | [] -> acc | x::xs -> loop (acc @+++ [xs]) xs in loop [list] list -
killerswan revised this gist
Apr 26, 2011 . 1 changed file with 2 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -49,4 +49,5 @@ let suffixesTR1 list = | x::xs -> loop xs (acc @++ [xs]) in loop list [list] (* This isn't really that much better than what we started with, of course. :D *) -
killerswan revised this gist
Apr 26, 2011 . No changes.There are no files selected for viewing
-
killerswan revised this gist
Apr 26, 2011 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -15,7 +15,7 @@ let suffixesTR list = | x::xs -> loop xs (acc @+ [xs]) in loop list [list] (* These can be rewritten from scratch... *) let myrev list = let rec loop acc list1 = match list1 with -
killerswan revised this gist
Apr 26, 2011 . 1 changed file with 36 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -14,3 +14,39 @@ let suffixesTR list = | [] -> acc | x::xs -> loop xs (acc @+ [xs]) in loop list [list] (* These can be rewritten... *) let myrev list = let rec loop acc list1 = match list1 with | [] -> acc | x::xs -> loop (x::acc) xs in loop [] list let myappend lis t = let rec loop acc list = match list with | [] -> acc | x::xs -> loop (x::acc) xs in loop t (myrev lis) (*...*) (* Or even more condensed *) let rec myrevappend acc list = match list with | [] -> acc | x::xs -> myrevappend (x::acc) xs let myappend1 lis t = myrevappend t (myrevappend [] lis) let suffixesTR1 list = let (@++) = myappend1 in let rec loop l acc = match l with | [] -> acc | x::xs -> loop xs (acc @++ [xs]) in loop list [list] (* This isn't really that much better than what we started with, of course. :D *) -
killerswan revised this gist
Apr 26, 2011 . 1 changed file with 6 additions and 5 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,15 +1,16 @@ (* This uses the @ operator (aka List.append) which is not tail recursive *) let suffixes list = let rec loop l acc = match l with | [] -> acc | x::xs -> loop xs (acc @ [xs]) in loop list [list] (* This uses an operator @+ constructed from two tail recursive methods... :P *) let suffixesTR list = let (@+) x y = List.rev_append (List.rev x) y in let rec loop l acc = match l with | [] -> acc | x::xs -> loop xs (acc @+ [xs]) in loop list [list] -
killerswan revised this gist
Apr 26, 2011 . 1 changed file with 12 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,6 +1,15 @@ let suffixes list = let rec loop l acc = match l with | [] -> acc | hd::tl -> loop tl (acc @ [tl]) in loop list [list] let suffixesTR list = let (@+) xs ys = List.rev_append (List.rev xs) ys in let rec loop list1 acc = match list1 with | [] -> acc | x::xs -> loop xs (acc @+ [xs]) in loop list [list] -
killerswan revised this gist
Apr 26, 2011 . 1 changed file with 2 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -2,6 +2,5 @@ let suffixesTR list = let rec loop l acc = match l with | [] -> acc | hd::tl -> loop tl (List.concat [acc; [tl]]) in loop list [list] -
killerswan revised this gist
Apr 26, 2011 . 1 changed file with 0 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -2,7 +2,6 @@ let suffixesTR list = let rec loop l acc = match l with | [] -> acc | hd::tl -> loop tl (List.concat [acc; [l]]) in loop list [] -
mneedham created this gist
Apr 26, 2011 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,8 @@ let suffixesTR list = let rec loop l acc = match l with | [] -> acc | [last] -> loop [] (List.concat [acc; [[last]]; [[]]]) | hd::tl -> loop tl (List.concat [acc; [l]]) in loop list []