You seem reasonably close. A few hints/remarks:
1) Aesthetically, using nil
in one line and []
in others seems odd. Either use all nil
or use all []
2) Since the input are lists of lists, in x::y::z
, the identifiers x
and y
would be lists of integers, rather than individual integers. Thus, x<y
wouldn't make sense. You can't compare lists of integers using <
.
3) Your problem description strongly suggests that the inner-lists are all 1-element lists. Thus you could use the pattern [x]::[y]::z
to allow you to compare x
and y
. In this case, x@y
could be replaced by [x,y]
4) If the inner lists are allowed to be of arbitrary size, then your code needs major revision and would probably require a full-fledged sort function to sort the result of concatenating pairs of inner lists. Also, in this case, the single list in the one inner list case should probably be sorted.
5) You have a typo: mergeP
isn't mergePass
.
On Edit:
If the sublists are each sorted (and the name of the overall function perhaps suggests this) then you need a function called e.g. merge
which will take two sorted lists and combine them into a single sorted list. If this is for a class and you have already seen a merge
function as an example (perhaps in a discussion of merge-sort) -- just use that. Otherwise you will have to write your own before you write this function. Once you have the merge function, skip the part of comparing x
and y
and instead have something as simple as:
| mergePass (xs::ys::zss) = (merge xs ys) :: mergePass zss
If the sublists are not merged, then you will need a full-fledged sort in which case you would use something like:
| mergePass (xs::ys::zss) = sort(xs @ ys) :: mergePass zss