I think you're assuming that this is more complicated than it is.
You're not supposed to do different things depending on the value of op
- op
is the ordering predicate you should use for merging and the predicate that the input lists are ordered by.
(In contrast to many other languages, symbols like <
or >
are not "special" in any way, they are identifiers just like less
, or greater
, or op
)
Here is a skeleton special case to get you started; the interesting bits are left as an exercise:
(define (merge [l1 : (Listof Number)]
[l2 : (Listof Number)]) : (Listof Number)
(cond [(empty? l1) l2] ;; If either list is empty,
[(empty? l2) l1] ;; the result is the other list.
[(< (first l1) (first l2)) ... fill this in ...]
[else ... fill this in ...]))
then, notice that this is equivalent to the code above:
(define op <)
(define (merge [l1 : (Listof Number)]
[l2 : (Listof Number)]) : (Listof Number)
(cond [(empty? l1) l2] ;; If either list is empty,
[(empty? l2) l1] ;; the result is the other list.
[(op (first l1) (first l2)) ... fill this in ...]
[else ... fill this in ...]))
and then you pass op
as a parameter instead, and you're done.