<div dir="auto">Makes sense to me!</div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, Sep 17, 2020, 12:59 PM Jon Purdy <<a href="mailto:evincarofautumn@gmail.com">evincarofautumn@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="auto">{ fromMaybe, fromLeft, fromRight, fromEither, fromThese, fromDynamic, … } extracts “the” value out of a { Maybe, These, Dynamic, … } with a suitable default if “it” isn’t present.<div dir="auto"><br></div><div dir="auto">These functions map a type onto the smallest product type that can represent the union of its possible values, taking defaults as needed to make the result total. They seem asymmetric at first glance because the structures of the input types differ, but they’re all doing the same thing.<div dir="auto"><br></div><div dir="auto">More to the point, anecdotally, I see Haskell beginners often reaching for accessor functions like ‘head’ and ‘fromJust’ before they’ve internalised pattern matching. They do use total combinators like ‘fromMaybe’ if available (and if they’re aware of them), because these combinators are more convenient than ‘if isJust … then fromJust … else …’, and they only happen to be safer incidentally. It’s the familiar “get value or default” pattern, if they’ve programmed before, nothing to do with totality. So it seems sensible to me to plug the hole in the taxonomy.</div></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, Sep 17, 2020, 6:34 AM Carter Schonwald <<a href="mailto:carter.schonwald@gmail.com" target="_blank" rel="noreferrer">carter.schonwald@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="auto">I’m not sure how fromMaybe relates here.  Could someone explain?</div><div dir="auto"><br></div><div dir="auto">For the anti-categorical folks who dislike codiag or related names like trace (in linear algebra trace is the sum of the diagonal of a matrix as a scalar, an apt analogy I think), another name that I think is descriptive is collapse </div><div dir="auto"><br></div><div dir="auto"><br></div><div dir="auto">Names bandied about so far: </div><div dir="auto"><br></div><div dir="auto">Dedup </div><div dir="auto">Codiag</div><div dir="auto">Fromeither </div><div dir="auto"><br></div><div dir="auto">Things I mentioned above : trace and collapse </div><div dir="auto"><br></div><div dir="auto">Zooming out though, this operation is equiv to “either id id”, so I don’t really see how inventing a new name for this specific tiny snippet really helps anyone. </div><div dir="auto"><br></div><div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, Sep 17, 2020 at 8:54 AM chessai <<a href="mailto:chessai1996@gmail.com" rel="noreferrer noreferrer" target="_blank">chessai1996@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="auto"><div>My instinct about fromEither's type was the same as Carter's, and I had to remind myself of fromMaybe. I like the name fromEither overall. Seems to fit well with precedent and is straightforward enough.<br><br><div class="gmail_quote"></div></div></div><div dir="auto"><div><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, Sep 17, 2020, 07:45 Oliver Charles <<a href="mailto:ollie@ocharles.org.uk" rel="noreferrer noreferrer" target="_blank">ollie@ocharles.org.uk</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><u></u><div><div>You may wish to compare with fromMaybe then, which probably also doesn't have the type you'd expect :) The type you have there is more like bifoldMap<br></div><div><br></div><div>On Thu, 17 Sep 2020, at 1:42 PM, Carter Schonwald wrote:<br></div><blockquote type="cite" id="m_-4149875199555143267m_3737276142332532469m_-8166797737212689159m_-7624924350472738924qt"><div dir="auto">I’d expect fromEither to be <br></div><div dir="auto">Either a b -> (a-> c )-> (b-> c) -> c <br></div><div dir="auto"><br></div><div dir="auto">Nothing about the name fromEither is suggestive of the Either a a type <br></div><div><div><br></div><div><div dir="ltr">On Thu, Sep 17, 2020 at 3:45 AM Oliver Charles <<a href="mailto:ollie@ocharles.org.uk" rel="noreferrer noreferrer noreferrer" target="_blank">ollie@ocharles.org.uk</a>> wrote:<br></div><blockquote style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0.8ex;border-left-color:rgb(204,204,204);border-left-style:solid;border-left-width:1px;padding-left:1ex"><div><u></u><br></div><div><div>Regardless of having a more abstract version, I'm +1 on Jon's suggestion, and those names. fromEither is something I have reached for many many times and been surprised it's not within arms reach.<br></div></div><div><div><br></div><div>On Thu, 17 Sep 2020, at 7:16 AM, Jon Purdy wrote:<br></div><blockquote type="cite" id="m_-4149875199555143267m_3737276142332532469m_-8166797737212689159m_-7624924350472738924qt-m_-456023475396536941qt"><div dir="auto"><div>I’m strongly for these:<br></div><div dir="auto"><br></div><div dir="auto">Data.Tuple.dup :: a → (a, a)<br></div><div dir="auto"><br></div><div dir="auto">Data.Either.fromEither :: Either a a → a<br></div></div></blockquote></div></blockquote></div></div></blockquote><div><br></div></div>_______________________________________________<br><br><br>Libraries mailing list<br><br><br><a href="mailto:Libraries@haskell.org" rel="noreferrer noreferrer noreferrer" target="_blank">Libraries@haskell.org</a><br><br><br><a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries" rel="noreferrer noreferrer noreferrer noreferrer" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries</a><br><br><br></blockquote></div></div></div><br><br></blockquote></div></div>
_______________________________________________<br>
Libraries mailing list<br>
<a href="mailto:Libraries@haskell.org" rel="noreferrer noreferrer" target="_blank">Libraries@haskell.org</a><br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries" rel="noreferrer noreferrer noreferrer" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries</a><br>
</blockquote></div>
_______________________________________________<br>
Libraries mailing list<br>
<a href="mailto:Libraries@haskell.org" target="_blank" rel="noreferrer">Libraries@haskell.org</a><br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries" rel="noreferrer noreferrer" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries</a><br>
</blockquote></div>