O'Reilly logo

Haskell Cookbook by Yogesh Sajanikar

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

How it works...

The mergeSort function is implemented in terms of a worker function mergeSort'This function is given a grouped list. This grouped list is a pairwise sorted list of lists created from input using the function group2. If mergeSort' receives an empty list, or a list with a single element (single list inside a list), then it returns it as a result. 

If mergeSort' receives a lists of list that contains more than one list, then it calls mergeStep' to pairwise merge adjacent lists to create another list of lists.

This can be shown graphically as follows:

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required