Browse thread
[Caml-list] tree walking with... specular rec functions? what else?
[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
| Date: | -- (:) |
| From: | John Carr <jfc@M...> |
| Subject: | Re: [Caml-list] tree walking with... specular rec functions? what else? |
I have a minor comment unrelated to the basic algorithm. > ... > let rec outer lst = > if (List.length lst) == 0 then () > else outer (inner lst []) > in > ... In general it is better to test for empty rather than compare the size of a collection to 0. With some collections (including lists) testing for empty takes constant time but computing size takes linear time. Instead of if (List.length lst) == 0 then empty-code else full-code either of these will be faster: if lst == [] then empty-code else full-code (match lst with [] -> empty-code | _ -> full-code) ------------------- To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ Beginner's list: http://groups.yahoo.com/group/ocaml_beginners