Re: [Haskell-cafe] Dynamically altering sort order

2009-05-03 Thread Denis Bueno
On Fri, Apr 24, 2009 at 19:49, Edward Kmett ekm...@gmail.com wrote: On Fri, Apr 24, 2009 at 5:11 PM, Denis Bueno dbu...@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

[Haskell-cafe] Dynamically altering sort order

2009-04-24 Thread Denis Bueno
Hi all, Suppose I have the following interface to a sorting function: sort :: (Ord a) = [a] - IO [a] -- sort large, on-disk array of records but I don't have a sortBy where you can simply pass a compare function. Wrapped around this is a command-line program which should allow the user to

Re: [Haskell-cafe] Dynamically altering sort order

2009-04-24 Thread Denis Bueno
On Fri, Apr 24, 2009 at 15:22, Martijn van Steenbergen mart...@van.steenbergen.nl wrote: 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

Re: [Haskell-cafe] Dynamically altering sort order

2009-04-24 Thread Martijn van Steenbergen
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 =

Re: [Haskell-cafe] Dynamically altering sort order

2009-04-24 Thread Martijn van Steenbergen
Denis Bueno wrote: The problem here is that the order is fixed. Statically. I can't change it at runtime based on flags. (Right? Unless I'm missing something) That is right. It might or might not be a problem in your specific case. sortBy :: (a - a - Ord) - [a] - IO [a] sortBy cmp =

Re: [Haskell-cafe] Dynamically altering sort order

2009-04-24 Thread wren ng thornton
Denis Bueno wrote: Hi all, Suppose I have the following interface to a sorting function: sort :: (Ord a) = [a] - IO [a] -- sort large, on-disk array of records but I don't have a sortBy where you can simply pass a compare function. Why don't you have sortBy? Wrapped around this is a

Re: [Haskell-cafe] Dynamically altering sort order

2009-04-24 Thread Edward Kmett
On Fri, Apr 24, 2009 at 5:11 PM, Denis Bueno dbu...@gmail.com wrote: Hi all, Suppose I have the following interface to a sorting function: sort :: (Ord a) = [a] - IO [a] -- sort large, on-disk array of records but I don't have a sortBy where you can simply pass a compare function.