<div dir="ltr">Can you explain why you think it's better to just define your own two-variant enum rather than having a built-in Either type, or point me to the evidence that Rust found in favor of this approach?<div><br></div><div>I had to create my own Either type for some code I wrote semi-recently and wished it was built in, so I'm wondering why I apparently shouldn't have wished that, but been glad that I'm creating my own.<br><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Dec 10, 2015 at 1:34 AM, Kevin Ballard via swift-evolution <span dir="ltr"><<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><u></u>
<div><div>I support the addition of a Result, and I encourage people to look at <a href="https://doc.rust-lang.org/stable/std/result/index.html" target="_blank">https://doc.rust-lang.org/stable/std/result/index.html</a> for a good example of how this can be done well. I'd like a Result<T,E> in Swift that looks similar.<br></div>
<div> </div>
<div>I do not support the addition of Either. As far as I am aware, the only compelling argument in favor of an Either type is "because Haskell has one", but I believe it's commonly recognized that Haskell's Either is not particularly good. It's a weird name for results (which Result covers), and for other cases it's usually better just to define your own two-variant enum anyway. Rust provides some evidence in favor of this, as this was the rationale for why Rust has a Result<T,E> but no Either, and it turns out there has been no need to add an Either.<br></div>
<div> </div>
<div>-Kevin Ballard</div><div><div>
<div> </div>
<div>On Wed, Dec 9, 2015, at 04:01 PM, T.J. Usiyan via swift-evolution wrote:<br></div>
<blockquote type="cite"><div dir="ltr">I hope that we can get both Either and Result into the standard lib. A great situation might be if Result were some sort of newtype declaration of Either.<br></div>
<div><div> </div>
<div><div>On Thu, Dec 10, 2015 at 5:25 AM, Developer via swift-evolution <span dir="ltr"><<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>></span> wrote:<br></div>
<blockquote style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div style="word-wrap:break-word"><div>There is! That’s what the Bifunctor typeclass is for. But if you had to pick just one of them to implement some Functor constraint - some canonical `map` function, would you pick the side that you filled with Errors, or the side that you filled with Values?<br></div>
<div><div><div> </div>
<div><div> </div>
<div><blockquote type="cite"><div>On Dec 9, 2015, at 6:52 PM, Jacob Bandes-Storch <<a href="mailto:jtbandes@gmail.com" target="_blank">jtbandes@gmail.com</a>> wrote:<br></div>
<div> </div>
<div><div dir="ltr"><div>Is there not precedent for having both "mapLeft<T>(f: L -> T) -> Either<T, R>" and "mapRight<T>(f: R -> T) -> Either<L, T>" ?<br></div>
<div><div> </div>
<div><div><div dir="ltr"><div>Jacob Bandes-Storch<br></div>
</div>
</div>
</div>
<div> </div>
<div><div>On Wed, Dec 9, 2015 at 3:49 PM, Developer <span dir="ltr"><<a href="mailto:devteam.codafi@gmail.com" target="_blank">devteam.codafi@gmail.com</a>></span> wrote:<br></div>
<blockquote style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div style="word-wrap:break-word"><div>How would you write `map` for an unbiased Either. You have to pick a side!<br></div>
<div> </div>
<div>Our implementation happens to be the one standardized on by Scala, Haskell, ML, (and to a limited extent) F#. For a less arbitrary reason, the use of "Right as Correct" is because Either, in all it’s Bifunctor-ial ways, has to admit two ways to map “across” itself. To paraphrase the words of a friend "There are lots of things in computer science we can leftMap”. In Haskell, such a thing is represented by the Functor typeclass, and due to the way type application works in that language, the convention has been to map over the rightmost side. But this isn’t Haskell, so our reasons can get even more theoretical than that (if you really want to get into what it looks like when you implement Covariant mapping down the left side of a common Bifunctor like Either, Cats has already had a thorough discussion on the subject: <a href="https://github.com/non/cats/issues/189" target="_blank">https://github.com/non/cats/issues/189</a>).<br></div>
<div><div><div> </div>
<div><div><blockquote type="cite"><div>On Dec 9, 2015, at 6:44 PM, Ilias Karim <<a href="mailto:ilias.karim@gmail.com" target="_blank">ilias.karim@gmail.com</a>> wrote:<br></div>
<div> </div>
<div><div style="word-wrap:break-word"><div>I’m sorry, I misunderstood. I guess an enum would be the appropriate choice, instead.<br></div>
<div> </div>
<div>As far as left/right goes, the decision to have left or right be the “correct” value is entirely arbitrary and should be left up to the developer. It should be a convention at best.<br></div>
<div> </div>
<div>Ilias<br></div>
<div><div> </div>
<div><blockquote type="cite"><div>On Dec 9, 2015, at 3:43 PM, Dave DeLong <<a href="mailto:delong@apple.com" target="_blank">delong@apple.com</a>> wrote:<br></div>
<div> </div>
<div><div style="word-wrap:break-word"><div>With a tuple, you have to do “(left: T?, right: U?)”, whereas with an Either you are guaranteed to always have one or other other; never both and never neither. That is not guaranteed with the tuple.<br></div>
<div> </div>
<div>Dave<br></div>
<div><div> </div>
<div><blockquote type="cite"><div>On Dec 9, 2015, at 4:41 PM, Ilias Karim via swift-evolution <<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>> wrote:<br></div>
<div> </div>
<div><div style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px">What are the advantage over using a tuple? One great feature about tuples is being able to name parameters so you can dispel ambiguity.<br></div>
<div style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"> </div>
<div> </div>
<div style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><blockquote type="cite"><div>On Dec 9, 2015, at 3:35 PM, Jacob Bandes-Storch <<a href="mailto:jtbandes@gmail.com" target="_blank">jtbandes@gmail.com</a>> wrote:<br></div>
<div> </div>
<div><div dir="ltr"><div>The idea of using Left/Right is to remain agnostic to what sorts of things users might want to put in. It's feasible a user might want Either<Int, String>, not just Either<ErrorType, T>.<br></div>
<div> </div>
<div><div>While I'm not sure Left & Right are the best choices, I don't think it's particularly worrisome when it comes to errors, as the general type-safety of the language will prevent users from mixing up success & error cases.<br></div>
<div><div> </div>
<div><div><div dir="ltr"><div>Jacob<br></div>
</div>
</div>
</div>
<div> </div>
<div><div>On Wed, Dec 9, 2015 at 3:32 PM, Ilias Karim via swift-evolution<span></span><span dir="ltr"><<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>></span><span></span>wrote:<br></div>
<blockquote style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div>Hi Robert,<br></div>
<div> </div>
<div>I agree with your recommendation of a generic Either type.<br></div>
<div> </div>
<div>However, I find your use of “Right” as the “Correct” value (whatever that means) of an instance of an Either type a little perplexing. While clever, it is exactly the kind of convention that easily leads to misunderstandings about the nature of the type itself ie. is it right and left or wrong and correct? At least that is my first impression after scanning your code.<br></div>
<div> </div>
<div>Ilias<br></div>
<div><div><div> </div>
<div>> On Dec 9, 2015, at 3:06 PM, Developer via swift-evolution <<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>> wrote:<br></div>
<div>><br></div>
<div>> It’s high time the STL admitted some kind of disjoint union type, at the very least because it’s such a minor addition it seems a shame to leave it out. Whatever feelings one may have about `throws`, the lack of standardizing on a datatype representing choice has caused the community to get creative and create many disjoint implementation of the same concept over and over and over again. To that end, I propose the STL ship with an Either type; We at TypeLift have already got our own we’d like to model it on (<a href="https://github.com/typelift/Swiftx/blob/master/Swiftx/Either.swift#L16" target="_blank">https://github.com/typelift/Swiftx/blob/master/Swiftx/Either.swift#L16</a>).<br></div>
<div>><br></div>
<div>><br></div>
<div>> ~Robert Widmann (CodaFi)<br></div>
<div>> _______________________________________________<br></div>
<div>> swift-evolution mailing list<br></div>
<div>><span></span><a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a><br></div>
<div>><span></span><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br></div>
<div> </div>
<div>_______________________________________________<br></div>
<div>swift-evolution mailing list<br></div>
<div><a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a><br></div>
<div><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br></div>
</div>
</div>
</blockquote></div>
<div> </div>
</div>
</div>
</div>
</div>
</blockquote></div>
<div> </div>
<div><img style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;min-height:1px!important;width:1px!important;border-top-width:0px!important;border-right-width:0px!important;border-bottom-width:0px!important;border-left-width:0px!important;margin-top:0px!important;margin-right:0px!important;margin-bottom:0px!important;margin-left:0px!important;padding-top:0px!important;padding-right:0px!important;padding-bottom:0px!important;padding-left:0px!important" border="0" height="1" width="1" alt="" src="https://www.fastmailusercontent.com/proxy/4df6c17a672dbc1d79d49d287594fe30b7741153e237ed5ade771b61cb74d019/8647470737a3f2f25723030323431303e23647e23756e64676279646e2e65647f27766f2f60756e6f35707e6d38777c4d223642474761705c627151396777615c633377447138346d407856683f62656d6a56565761394478515930744e4d223248645b6431533467603778677177556b6d405174395f60525575505d4462776873697b49387559453e41477a43424e4d6d2232474e40374474707d22324566414643324b4d22324277484a68577c626e686566533745544676525d4e65365e6b60525963443240366a663832737a7c4156565f6a6240746d655e6772755f4731336a7945693d2232425d6f446d22324353465a61723f4d423854736336756b417678534245623a627d4e43454e403c4b444053373240345a7d22324a40364e686c6e4867763f455d23344/open"><span style="font-family:Helvetica"><span style="font-size:12px"><span></span></span></span><span style="font-family:Helvetica"><span style="font-size:12px">_______________________________________________</span></span><br></div>
<div><span style="font-family:Helvetica"><span style="font-size:12px">swift-evolution mailing list</span></span><br></div>
<div><a style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px" href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a><br></div>
<div><a style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px" href="https://lists.swift.org/mailman/listinfo/swift-evolution" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br></div>
</div>
</blockquote></div>
<div> </div>
</div>
</div>
</div>
</blockquote></div>
<div> </div>
</div>
</div>
</div>
</blockquote></div>
<div> </div>
</div>
</div>
</div>
</div>
</blockquote></div>
<div> </div>
</div>
</div>
</div>
</blockquote></div>
<div> </div>
</div>
<div><img style="min-height:1px!important;width:1px!important;border-top-width:0px!important;border-right-width:0px!important;border-bottom-width:0px!important;border-left-width:0px!important;margin-top:0px!important;margin-bottom:0px!important;margin-right:0px!important;margin-left:0px!important;padding-top:0px!important;padding-bottom:0px!important;padding-right:0px!important;padding-left:0px!important" border="0" height="1" width="1" alt="" src="https://www.fastmailusercontent.com/proxy/eaf8391373f58c23a00e2cd63ddca2382cb6699f0eab09dea9e411831e753659/8647470737a3f2f25723030323431303e23647e23756e64676279646e2e65647f27766f2f60756e6f35707e6d333647466f63605267687b6e4b6d6a6567346a636b676939477d223247495953385632587a41347b65585b434f6f6d6a717444665360566a69314555447d223242315d22364c413d223647375651725c6c4630597857744e68676d466537636e667a464e474778573f68456a71624d22364e483a54583e4d2236456d4f6b62454a49396864653378764937474247683d647f6861623c4257735d466237567a754c603a674a76663231347979696759623a7d223641614f4c6b646338594d2232466b45717039673d4d6a577f4c67575a425d2236447f445d223641776d603d2236475a667838326a7e69487252646b66795878565576537d4c617a624774665e614d23344/open"><br></div>
</div>
</div>
</div>
<div> </div>
<div>_______________________________________________<br></div>
<div>
swift-evolution mailing list<br></div>
<div> <a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a><br></div>
<div> <a href="https://lists.swift.org/mailman/listinfo/swift-evolution" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br></div>
<div> </div>
</blockquote></div>
</div>
<div><img style="min-height:1px!important;width:1px!important;border-top-width:0px!important;border-right-width:0px!important;border-bottom-width:0px!important;border-left-width:0px!important;margin-top:0px!important;margin-bottom:0px!important;margin-right:0px!important;margin-left:0px!important;padding-top:0px!important;padding-bottom:0px!important;padding-right:0px!important;padding-left:0px!important" border="0" height="1" width="1" alt="" src="https://www.fastmailusercontent.com/proxy/dac11682feb81afe48fd1697c255e91cacf8027bfe0f5271f04d9fc45023e85f/8647470737a3f2f25723030323431303e23647e23756e64676279646e2e65647f27766f2f60756e6f35707e6d3148765176786c673171614a7d2236454230345272776e416d22324a503b62713275693462445d223643763d6a483148796f4a5e4b4b446950314161784f6a6e6d22324477393164614c403935386c4d223648457c49745452767867697438513b40743d22364c4c6d4167507c64496876403d666b637176723a7f6a623932336a40375957617b657535345639617631786a4a6558664b4d2232407030365c4436356a4d6b43414935326a4664665c4b69547f6d22364c4867617565707442694035303450536278683a4837536a693443766347775946423837495c444f4267725e47386f614d23344d23344/open"><br></div>
<div><u>_______________________________________________</u><br></div>
<div>swift-evolution mailing list<br></div>
<div><a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a><br></div>
<div><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br></div>
</blockquote><div> </div>
<img src="https://u2002410.ct.sendgrid.net/wf/open?upn=Kyo40-2Fb6mK7qqe0u18o4nlmNW45gwtJGUNOsveb6UxNIz3Kk-2BnN6xYRMl0ogAPwyNCvSyc8NpF8AtzUSPUARBs8Qki8LEvltC5ipPaudKcIKtFxgCisoobKHRYzP6Ai2gxgSwMnPynjwTVs0JFawaA3EQaOxZT6JeWBSeWwFQMZJgMWYVkC8MQNjkES-2FYW0oozf8D-2BdHor8oEbK0sSNVNnCpyr3ERRte4OWHkPcf5Og-3D" alt="" width="1" height="1" border="0" style="min-height:1px!important;width:1px!important;border-width:0!important;margin-top:0!important;margin-bottom:0!important;margin-right:0!important;margin-left:0!important;padding-top:0!important;padding-bottom:0!important;padding-right:0!important;padding-left:0!important">
</div></div></div>
<br>_______________________________________________<br>
swift-evolution mailing list<br>
<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a><br>
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br>
<br></blockquote></div><br></div></div></div>