
2 May
2009
2 May
'09
9:38 p.m.
On Fri, Apr 24, 2009 at 19:49, Edward Kmett
On Fri, Apr 24, 2009 at 5:11 PM, Denis Bueno
wrote: Is there an Ord instance that can be dynamically changed in this way?
My first idea is something like this:
data CompareRecord = CR{ rCompare :: Record -> Record -> Ordering, unCR :: Record } instance Ord CompareRecord where compare (CR cmp x) (CR _ y) = cmp x y
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?
You can make a safer 'CompareRecord' using 'reflection' from hackage:
This is what I ended up doing and it worked out great. Thanks for the suggestion. Denis