<div dir="auto">"Nothing" uses the same memory slot no matter how many times it's used, but "Left ()" will more than likely create a new object every time, or at the very least one for each module where it's used.<div dir="auto"><br></div><div dir="auto">Eq and Ord instances get slightly slower because they have to compare () with () every time they receive a pair of Lefts.</div><div dir="auto"><br></div><div dir="auto">Where you would pass "x" into the "maybe" deconstructor function, now you would have to pass "const x" to "either", which again uses more memory and (more importantly) more cognitive space.</div><div dir="auto"><br></div><div dir="auto">We have the problem other people have mentioned where FlexibleInstances or TypeFamilies/GADTs have to be used to define instances for Either ().</div><div dir="auto"><br></div><div dir="auto">However, the biggest problem is that Maybe is not actually isomorphic to Either () in a lazy language like Haskell. Maybe has</div><div dir="auto"><br></div><div dir="auto">* Nothing</div><div dir="auto">* Just x</div><div dir="auto"><br></div><div dir="auto">However, Either () has</div><div dir="auto"><br></div><div dir="auto">* Left ()</div><div dir="auto">* Right x</div><div dir="auto">* Left undefined</div><div dir="auto"><br></div><div dir="auto">And that final value causes infinite problems, particularly when you pass it to other functions which handle strictness on the Left argument differently. Is the Eq () instance strict or lazy in its arguments? I honestly would not be able to tell you without firing up an instance of GHCi. I've seen different libraries which define singleton objects define it in different ways.</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Fri, May 29, 2020, 05:40 Henning Thielemann <<a href="mailto:lemming@henning-thielemann.de">lemming@henning-thielemann.de</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br>
On Fri, 29 May 2020, Wiebe-Marten Wijnja wrote:<br>
<br>
> Greetings, everyone!<br>
><br>
> Recently I was involved in a discussion on the new ML-style language<br>
> 'gleam'.<br>
><br>
> Gleam has for quite a while now only had an `Either a b` type,<br>
> with all functions that in Haskell one would use a `Maybe a` for,<br>
> working on an `Either a ()` instead.<br>
<br>
In Haskell `Maybe a` is more similar to `Either () a` than `Either a ()`.<br>
<br>
Either has one more redirection on the Left case. You can have both `Left <br>
undefined` and `Left ()` whereas Maybe can only have `Nothing`. I hardly <br>
think that people actually make use of this difference, though.<br>
<br>
Btw. from a software engineering point I'd prefer not to use Either for <br>
both exception handling with an according Monad and for cases where you <br>
just want to handle values of two possible types. I'd define an Except <br>
type for the exception usage.<br>
<br>
Could we remove Maybe in favor of Either? It would make some instances <br>
non-Haskell-98. E.g.<br>
<br>
instance C Maybe where<br>
<br>
is Haskell 98, but<br>
<br>
instance C (Either ()) where<br>
<br>
needs FlexibleInstances and<br>
<br>
instance (a ~ ()) => C (Either a) where<br>
<br>
needs TypeFamilies.<br>
<br>
Unless you find out that you can define a more general instance like<br>
<br>
instance (Super a) => C (Either a) where<br>
<br>
.<br>
_______________________________________________<br>
Haskell-Cafe mailing list<br>
To (un)subscribe, modify options or view archives go to:<br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe" rel="noreferrer noreferrer" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe</a><br>
Only members subscribed via the mailman list are allowed to post.</blockquote></div>