Re: Adding a "Map k a -> Set (Arg k a)" function to containers
David Feuer <[email protected]> Thu, 27 Jan 2022 20:34:15 -0500
| Newsgroups | gmane.comp.lang.haskell.libraries |
|---|---|
| Message-ID | <CAMgWh9vhDg-5N5U+NqKEtfPKAks0eyZL0UJ2dkM8pM3Vm_z0fA@mail.gmail.com> |
--===============7334071716861257731== Content-Type: multipart/alternative; boundary="00000000000079805505d69a6fe8" --00000000000079805505d69a6fe8 Content-Type: text/plain; charset="UTF-8" I have one minor operational concern. Set is strict in its keys, so code doesn't have to check whether a key is evaluated when case matching on it. Arg, on the other hand, is lazy in both arguments. So this function throws away evaluatedness information, which is always a bit sad. Separately, I'd love see: 1. A function going the other way. 2. Unsafe mapMonotonic-style functions generalizing both. On Thu, Jan 27, 2022, 8:25 PM Joseph C. Sible <[email protected]> wrote: > I opened https://github.com/haskell/containers/issues/814 about adding > this function to the containers package: > > import qualified Data.Map.Internal as Map > import qualified Data.Set.Internal as Set > import Data.Semigroup (Arg(..)) > > mapToArgSet :: Map.Map k a -> Set.Set (Arg k a) > mapToArgSet Map.Tip = Set.Tip > mapToArgSet (Map.Bin sz k v l r) = Set.Bin sz (Arg k v) (mapToArgSet > l) (mapToArgSet r) > > Does anyone have any suggestions or improvements for this? In > particular, I'm sure there's a less clunky name that I just can't > think of. > > Thanks, > > Joseph C. Sible > _______________________________________________ > Libraries mailing list > [email protected] > http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries > --00000000000079805505d69a6fe8 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable <div dir=3D"auto">I have one minor operational concern. Set is strict in it= s keys, so code doesn't have to check whether a key is evaluated when c= ase matching on it. Arg, on the other hand, is lazy in both arguments. So t= his function throws away evaluatedness information, which is always a bit s= ad.<div dir=3D"auto"><br></div><div dir=3D"auto">Separately, I'd love s= ee:</div><div dir=3D"auto"><br></div><div dir=3D"auto">1. A function going = the other way.</div><div dir=3D"auto">2. Unsafe mapMonotonic-style function= s generalizing both.</div></div><br><div class=3D"gmail_quote"><div dir=3D"= ltr" class=3D"gmail_attr">On Thu, Jan 27, 2022, 8:25 PM Joseph C. Sible <= ;<a href=3D"mailto:[email protected]">[email protected]</a>> w= rote:<br></div><blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex= ;border-left:1px #ccc solid;padding-left:1ex">I opened <a href=3D"https://g= ithub.com/haskell/containers/issues/814" rel=3D"noreferrer noreferrer" targ= et=3D"_blank">https://github.com/haskell/containers/issues/814</a> about ad= ding<br> this function to the containers package:<br> <br> import qualified Data.Map.Internal as Map<br> import qualified Data.Set.Internal as Set<br> import Data.Semigroup (Arg(..))<br> <br> mapToArgSet :: Map.Map k a -> Set.Set (Arg k a)<br> mapToArgSet Map.Tip =3D Set.Tip<br> mapToArgSet (Map.Bin sz k v l r) =3D Set.Bin sz (Arg k v) (mapToArgSet<br> l) (mapToArgSet r)<br> <br> Does anyone have any suggestions or improvements for this? In<br> particular, I'm sure there's a less clunky name that I just can'= ;t<br> think of.<br> <br> Thanks,<br> <br> Joseph C. Sible<br> _______________________________________________<br> Libraries mailing list<br> <a href=3D"mailto:[email protected]" target=3D"_blank" rel=3D"noreferre= r">[email protected]</a><br> <a href=3D"http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries" rel= =3D"noreferrer noreferrer" target=3D"_blank">http://mail.haskell.org/cgi-bi= n/mailman/listinfo/libraries</a><br> </blockquote></div> --00000000000079805505d69a6fe8-- --===============7334071716861257731== Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: base64 Content-Disposition: inline X19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX18KTGlicmFyaWVz IG1haWxpbmcgbGlzdApMaWJyYXJpZXNAaGFza2VsbC5vcmcKaHR0cDovL21haWwuaGFza2VsbC5v cmcvY2dpLWJpbi9tYWlsbWFuL2xpc3RpbmZvL2xpYnJhcmllcwo= --===============7334071716861257731==--