How can I sort list with IO Compare function?
sortWith :: [String] -> (String -> String -> IO Ordering) -> IO [String]
Sortby expects (a->a->Ordering) and I don’t know, how to deal with it. I am too lazy to implement quick sort myself.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
I’m afraid there is no simple way. If it was possible to lift
to
you could see the order of comparisons in implementation of
sortBy, violating referential transparency.In general, it’s easy to go from
xxxMtoxxxbut not conversely.Possible options:
unsafePerformIOas a hackSwitch to sorting by key and use the Schwartzian transform