Aaron says
> Syssort is an example of an enormously useful higher order function. It
> was written on the assumption that there was no need for its author to
> think about the types of the elements of the lists or the types of the
> arguments of the predicate. That responsibility can be left to the
> programmer who provides the ordering predicate, and if she wants the
> list to contain an arbitrary mixture of types of entities, that's fine,
> as long as the predicate supplied can handle any combination of them.
> I understand you can't do that in ML, despite its support for
> polymorphic types.
Well, you can write syssort in SML to take a order predicate,
and a list producing a sorted list.
syssort : ('a -> bool) -> 'a list -> 'a list
However you don't have undiscriminated unions in SML, so the
thingies to be sorted have to be a single type.
syssort([8 cat 7 bee 1], isbefore)
would have to be rendered
syssort isbefore [I 8, V "cat", I 7, V "bee", I 1]
where I and V are constructors that convert int's and strings
into a single type ("token" or "item", say). One can mimic POP's
dynamic type system in SML with a big discriminated union,
and even get something like a reasonable succinctness of notation
syssort isbefore
(popobj "[8 cat 7 bee 1 elephant 3 4 dog ant bat]")
where popobj is a function that converts a string into a
list of these objects.
|