merge xs ys =
recursionEngine
(\(xs, ys) -> null xs || null ys)
(\(xs, ys) -> xs ++ ys)
(:)
(\(x:xs, y:ys) -> min x y)
(\(x:xs, y:ys) -> if x <= y then (xs, y:ys) else (x:xs, ys))
(xs, ys)
I'm not sure how to translate that into the genPR formulation.
merge xs ys =
genPR
(\(xs, ys) -> null xs || null ys)
(\(x:xs, y:ys) -> if x <= y then (xs, y:ys) else (x:xs, ys))
<There is no constant that goes here.>
(\(x:xs, y:ys) merged -> (min x y) : merged)
Besides the problem with the third argument, the fourth argument is awkward since it must take both heads, take their min, and then add them to the result of the recursive call. I'd prefer to take the heads and the min in a separate step as in the fourth argument to recursionEngine.