I cannot create the descendingSort function that is shown on that page.
My quicksort function looks like this:
quickSort2 _ [] = [] quickSort2 c (x:xs) = (quickSort2 c less) ++ (x:equal) ++ (quickSort2 c more) where less = filter (\y -> y `c` x == LT) xs equal = filter (\y -> y `c` x == EQ) xs more = filter (\y -> y `c` x == GT) xs
descending looks like this:
descending x y = compare y x
I put the two together to get the descendingSort function. This is where I get the error.
descendingSort = quickSort2 descending
(Error message from ghci):
Quote
test2.hs:102:28:
Ambiguous type variable `a' in the constraint:
`Ord a' arising from a use of `descending' at test2.hs:102:28-37
Possible cause: the monomorphism restriction applied to the following:
descendingSort :: [a] -> [a] (bound at test2.hs:102:0)
Probable fix: give these definition(s) an explicit type signature
or use -fno-monomorphism-restriction
Failed, modules loaded: none.
Ambiguous type variable `a' in the constraint:
`Ord a' arising from a use of `descending' at test2.hs:102:28-37
Possible cause: the monomorphism restriction applied to the following:
descendingSort :: [a] -> [a] (bound at test2.hs:102:0)
Probable fix: give these definition(s) an explicit type signature
or use -fno-monomorphism-restriction
Failed, modules loaded: none.
I don't really understand the error message. As mentioned in the wiki, descendingSort's type signature is supposed to be [a] -> [a], right? What am I doing wrong?

New Topic/Question
Reply



MultiQuote





|