-
-
Save killerswan/941923 to your computer and use it in GitHub Desktop.
Purely Functional Data Structures - Chris Okasaki
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 characters
(* 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] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment