I am writing this function:
||| Returns the ten largest values in the list.
top_ten : Ord a => List a -> List a
My first attempt was a pointfree implementation using function composition:
top_ten = take 10 . reverse . sort
But this gave the following error:
Main.idr:3:9:When checking right hand side of top_ten with expected type
List a -> List a
Can't disambiguate name: Prelude.List.take, Prelude.Stream.take
My second attempt was a straightforward pointed implementation:
top_ten xs = take 10 (reverse (sort xs))
That works, as do these:
top_ten xs = take 10 $ reverse $ sort xs
top_ten xs = take 10 (reverse $ sort xs)
top_ten xs = take 10 $ reverse . sort $ xs
top_ten xs = take 10 (reverse . sort $ xs)
However, these do not:
top_ten xs = take 10 . reverse $ sort xs
top_ten xs = take 10 . reverse . sort $ xs
top_ten xs = take 10 $ (reverse . sort) xs
top_ten xs = (take 10 . reverse) (sort xs)
top_ten xs = take 10 ((reverse . sort) xs)
What exactly is going on here? What is causing these equivalent expressions to have different levels of ambiguity?