<html>
<head>
<meta content="text/html; charset=ISO-8859-1"
http-equiv="Content-Type">
<style id="EHTipGlobalStyle">.EHTipToolTip * {background: inherit;font-family: inherit;font-size: inherit;font-size-adjust: none;font-stretch: normal;line-height: inherit;font-variant: normal;border: 0px;text-transform: inherit;color: inherit;font-style: inherit;text-decoration: inherit;margin: 0px 0px 0px 0px;padding: 0px 0px 0px 0px;float: none;display: inline;cursor: default;}
.EHTipReplacer, .EHTipKey, .EHTipAudio {cursor: pointer;}
.EHTipToolTip hr {margin: 0.4em 0;display: block;border: 1px inset;}
.EHTipTranslation {font-style: normal;}
.EHTipTranslation a {color: #000099;font-style: normal;text-decoration: none;}
.EHTipTranslation a:hover {background: inherit;color: #000000;text-decoration: underline;}
</style>
</head>
<body style="background-color: rgb(255, 255, 255); color: rgb(0, 0,
0);" bgcolor="#FFFFFF" text="#000000">
Hi Patrick,<br>
<br>
Due to my poor wording of the question (and the choice of String,
instead of unit or Void, for Left), this discussion went the wrong
way. Completely.<br>
I also noticed that some of my comments went in the "usage"
direction.<br>
<br>
My intent was to ask the question about implementation of Maybe,
*not it's usage*. Seems that most people understood that I'm arguing
whether the Maybe is needed and/or should it be switched with
Either. I'm not.<br>
<br>
However, what I was trying to find out were the reasons for the way
it is *implemented*. When I look at the code for Maybe and Either,
it seems to me like the violation of the "do not repeat yourself"
principle. That principle is taken rather seriously in Haskell. Even
HLint has "Reduce duplication" suggestion. *Some* of the code I
looked at appears the same.<br>
<br>
I wanted to find out what were the
reasons/restrictions/functionalities why Maybe wasn't (somehow)
built on Either, so there will be less code duplication.<br>
<br>
The first reason would be that there are no data constructor
synonyms, so it will not be elegant (although, that might be solved
with PatternSynonyms, as Ben Gamari suggested).<br>
<br>
The other reason, that probably couldn't be solved, was pointed out
by Nickolay Kudasov, and that is the generic functions like Show
(for Left String) and probably more, like Read.<br>
<br>
<br>
vlatko<br>
<br>
<blockquote style="border-left: 2px solid #330033 !important;
border-right: 2px solid #330033 !important; padding: 0px 15px 0px
15px; margin: 8px 2px;"
cite="mid:CADJNe+mP4Pc1xXRCeDDSwbMdOQqZB7sn2UyVtkv7sHoGd_=QSQ@mail.gmail.com"
type="cite"><!--[if !IE]><DIV style="border-left: 2px solid #330033; border-right: 2px solid #330033; padding: 0px 15px; margin: 2px 0px;"><![endif]--><span
style="color:#000000;" class="headerSpan">
<div class="moz-cite-prefix">-------- Original Message --------<br>
Subject: Re: [Haskell-cafe] Why Maybe exists if there is
Either?<br>
From: Patrick Hurst <a class="moz-txt-link-rfc2396E" href="mailto:lightquake@amateurtopologist.com"><lightquake@amateurtopologist.com></a><br>
To: <a class="moz-txt-link-abbreviated" href="mailto:vlatko.basic@gmail.com">vlatko.basic@gmail.com</a><br>
Cc: <a class="moz-txt-link-rfc2396E" href="mailto:haskell-cafe@haskell.org">"haskell-cafe@haskell.org"</a>
<a class="moz-txt-link-rfc2396E" href="mailto:haskell-cafe@haskell.org"><haskell-cafe@haskell.org></a><br>
Date: 09.01.2014 21:57<br>
</div>
<br>
<br>
</span>
<div dir="ltr">Why have Bool? Just let true = 1, false = 0, (||) =
(+), (&&) = (*).
<div><br>
</div>
<div>Why have Ordering? Just use Integer and let lt = -1, eq =
0, gt = 1.</div>
<div><br>
</div>
<div>Why have three-tuples (a, b, c)? Just use ((a, b), c).</div>
<div><br>
</div>
<div>Why have Data.Map a b? Just use a -> Maybe b. You don't
even need an Ord constraint any more!</div>
<div><br>
</div>
<div>Why have Data.Set a? Just use a -> Bool (or, a ->
Integer).</div>
<div>
<br>
</div>
<div>For that matter, why use algebraic data types? data Person
= Person String Int is isomorphic to type Person = (String,
Int).</div>
<div><br>
</div>
</div>
<div class="gmail_extra"><br>
<br>
<div class="gmail_quote">
On Thu, Jan 9, 2014 at 9:50 AM, Vlatko Basic <span dir="ltr"><<a
moz-do-not-send="true"
href="mailto:vlatko.basic@gmail.com" target="_blank">vlatko.basic@gmail.com</a>></span>
wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0
.8ex;border-left:1px #ccc solid;padding-left:1ex">
Hello Cafe,<br>
<br>
With my current knowledge of Haskell, I do not see why is
there Maybe if we have Either.<br>
<br>
For example, Functor and Monad instances (and many others)
of Maybe and Either are the same (except for fail).<br>
<br>
In other words, this should hold:<br>
<br>
Maybe a = Either String a -- String or something
else<br>
Nothing = Left ""<br>
Just a = Right a<br>
<br>
<br>
I'm curious to find out what was the reasoning to make
Maybe?<br>
What is the added value with introducing it?<br>
In which situations the above substitution does not hold?<br>
<br>
<br>
<br>
Best regards,<br>
<br>
vlatko<br>
<br>
_______________________________________________<br>
Haskell-Cafe mailing list<br>
<a moz-do-not-send="true"
href="mailto:Haskell-Cafe@haskell.org" target="_blank">Haskell-Cafe@haskell.org</a><br>
<a moz-do-not-send="true"
href="http://www.haskell.org/mailman/listinfo/haskell-cafe"
target="_blank">http://www.haskell.org/mailman/listinfo/haskell-cafe</a><br>
</blockquote>
</div>
<br>
</div>
<!--[if !IE]></DIV><![endif]--></blockquote>
<br>
</body>
</html>