Hi Denis,

Denis Bueno wrote:
where the rCompare field would be a function that is based on the
flags passed to the command-line problem.  But this has an ugly
asymmetry.  Does anyone have any other ideas?

Here's a solution that is more symmetrical but not necessarily prettier:

newtype Wrap = Wrap { unwrap :: Record }

instance Ord Wrap where
  ... your compare function here ...

But I don't think there's anything wrong with your original solution. You can write your own sortBy and hide (not export) the CompareRecord type:

sortBy :: (a -> a -> Ord) -> [a] -> IO [a]
sortBy cmp = map unCR . sort . map (CompareRecord cmp)

HTH,

Martijn.
_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to