[Haskell-cafe] A quick question about distribution of finite maps.

Ignat Insarov kindaro at gmail.com
Sat Jan 9 08:38:00 UTC 2021


Hello!

Finite maps from `"containers" Data.Map` look like they may form a
Cartesian closed category. So it makes sense to ask if the rule _α ⇸
(β ⇸ γ) ≡ ⟨α; β⟩ ⇸ γ ≡ ⟨β; α⟩ ⇸ γ ≡ β ⇸ (α ⇸ γ)_ that holds in such
categories does hold for finite maps. Note that, a map being a
functor, this also may be seen as _f (g α) ≡ g (f α)_, which would
work if maps were `Distributive` [1].

It looks to me as though the following definition might work:

    distribute = unionsWith union . mapWithKey (fmap . singleton)

— And it works on simple examples. _(I checked the law `distribute ∘
distribute ≡ id` — it appears to be the only law required.)_

Is this definition correct? Is it already known and defined elsewhere?

[1]: https://hackage.haskell.org/package/distributive-0.6.2.1/docs/Data-Distributive.html#t:Distributive


More information about the Haskell-Cafe mailing list