From: John M. S. <sk...@oz...> - 2003-06-17 02:15:48
|
Brian Hurt wrote: > On Mon, 16 Jun 2003, Nicolas Cannasse wrote: >I'm treading dangerously close to saying "if > you're using fold_right, you're screwing up. One of List.map, Enum.map, > or List.fold_left is what you really want to be using." It depends on context. Generally I use whatever is easiest to read and write, becaise generally I am dealing with lists of 0-10 elements, with 0-3 being 99% of the cases (number of parameters a function has in a typical program, number of components in a product type) Sometimes I have slightly longer lists, for example: list of all tokens in the program: that's typically in the 1000's. Vyper actually did something like 10 sub-folds over the input token stream, mainly to get it into a shape that could be LALR-parsed. Still, matching on the list was probably more of an issue than tail recursion for the optimising compiler: the bytecode compiler crashed out of stack space when one of my iterations wasn't tail rec, but consuming 10 Meg of stack isn't a big deal for a binary on a single user machine with 64Meg real. Now, appending one elements to the end of the token list, on the other hand, would be a disaster. I dun mind a constant number of O(n) operations, but n log n where n is in the 1000s is a much bigger number .. a resize array would be much faster. Ocaml doesn't have one. Nor mutable doubly-linked lists or other simple data structures that would sometimed be very convenient, but a pain to define and then redefine in the next project .. BTW: lost the web site. Please put web site address in the signature. -- John Max Skaller, mailto:sk...@oz... snail:10/1 Toxteth Rd, Glebe, NSW 2037, Australia. voice:61-2-9660-0850 |