Proposal #2659: Add sortOn and friends to Data.List

Henning Thielemann lemming at henning-thielemann.de
Fri Oct 10 05:03:25 EDT 2008


On Mon, 6 Oct 2008, Jean-Philippe Bernardy wrote:

> How about capturing the pattern in higher order functions?
>
> if we define:
>
>> import Data.Function
>> import Data.List
>
>> data Cache b a = Cache b a
>> fromCache (Cache _ a) = a
>> toCache f a = Cache (f a) a
>> cache (Cache b _) = b
>
>> caching f g = map fromCache . g . map (toCache f)

I've already done this with plain pairs - a distinct type like Cache is of 
course better. See attachKey:
   http://darcs.haskell.org/htam/src/Useful.hs



More information about the Libraries mailing list