Explain this 'Merge' Function in Haskell

Viewed 2437

I am learning Haskell and I am having trouble understanding this function. I am implementing mergesort. I have the mergesort recursive function implemented, but I don't understand what this 'merge' function is doing. I understand merge sort in an imperative language, but I don't understand the syntax here.

merge []         ys                   = ys
merge xs         []                   = xs
merge xs@(x:xt) ys@(y:yt) | x <= y    = x : merge xt ys
                          | otherwise = y : merge xs yt
3 Answers
Related