|
Is there actually no way to write functions like a generic three-way compare?Sure. You have to feed the two-way comparison operation in as a parameter. Is the lexcomp function defined locally in anadict supposed to be different from the globally defined lexcomp? My inclination is to assume that they should be different, because otherwise there'd be no point in having two definitions, but I can't imagine how two functions with that name could differ.They can probably be the same, but you should figure this out based on the requirements of anadict. It's generally better style to bundle all of the special function definitions needed by something like anadict as local definitions, unless they can be made really global and put into libraries for widespread use.
In the skeleton definition of anasort, there are ellipses in front of, between and behind the two (explode ...) calls. Does that mean that a solution that only inserts things in the first two positions will be wrong? Or is the final ellipsis just for closing parentheses?I put ellipses wherever I deleted anything, including parentheses. The problem statement for the second problem mentions pairs in the second to last sentence, and the anadict skeleton has a local makeanapair function, but the rest of the problem statement only mentions a list with sublists. Are the pairs hd/tl pairs, or is the result supposed to be (string * string list) list, with the first string in each list the anagram-canonical form?"hd/tl pairs" doesn't make sense, because the hd of a list is in the element type, while the tl is in the list type. It works pretty well with either lists of length two or ordered pairs, both of which are built-in to ML. I suggest lists of length two just because that way you do everything with lists and don't need to worry about ordered pair notation.
Mike O'D. |
to: