Minor containers API changes

wren ng thornton wren at freegeek.org
Fri Dec 2 18:38:55 CET 2011


On 12/2/11 12:28 PM, wren ng thornton wrote:
> On 11/30/11 7:51 AM, Felipe Almeida Lessa wrote:
>> On Wed, Nov 30, 2011 at 4:54 AM, Liyang HU<haskell.org at liyang.hu> wrote:
>>> How about using the Down/Dual/Desc/Converse/Opposite/Reverse newtype
>>> discussed
>>> in another recent thread, and providing for Data.Map:
>>>
>>> reverse :: Map k a -> Map (Reverse k) a
>>> reverse Tip = Tip
>>> reverse (Bin n k a l r) = Bin n (Reverse k) a (reverse r) (reverse l)
>>>
>>> (Arguably we also need reverse' :: Map (Reverse k) a -> Map k a. Hmm...)
>>
>> reverse' :: Map (Reverse k) a -> Map k a
>> reverse' = unsafeCoerce . reverse
>>
>> Sorry, couldn't resist =).
>
> As an addendum to the mapKeysAntitonic proposal, we should add the
> functorial rewrite rules which account for mono-/antitonicity.
>
> {-# RULES
> "mapKeysAntitonic id"
> mapKeysAntitonic id = id
>
> "mapKeysAntitonic f . mapKeysAntitonic g"
> mapKeysAntitonic f . mapKeysAntitonic g
> = mapKeysMonotonic (f . g)

Whoops, forgot the other two fusions:

     "mapKeysAntitonic f . mapKeysMonotonic g"
         mapKeysAntitonic f . mapKeysMonotonic g
             = mapKeysAntitonic (f . g)

     "mapKeysMonotonic f . mapKeysAntitonic g"
         mapKeysMonotonic f . mapKeysAntitonic g
             = mapKeysAntitonic (f . g)

I know older GHC had an eta problem that led to the need for separate 
"f.g" and "f/g" forms of rules. I'm not sure whether that's still an 
issue or not though.

-- 
Live well,
~wren



More information about the Libraries mailing list