Mergesort implemented using functional programming concepts