[Haskell-cafe] Dynamically altering sort order

Denis Bueno dbueno at gmail.com
Sat May 2 21:38:33 EDT 2009

On Fri, Apr 24, 2009 at 19:49, Edward Kmett <ekmett at gmail.com> wrote:
> On Fri, Apr 24, 2009 at 5:11 PM, Denis Bueno <dbueno at gmail.com> 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


More information about the Haskell-Cafe mailing list