<div dir="ltr">For what its worth I wrote this a while back, a hopeless attempt to do something "monad like" in PHP but reading it again..... well, it's no wonder I like Haskell more than I like having to use PHP!<br><br><a href="http://objitsu.blogspot.co.uk/2013/01/php-and-maybe-miserable-monads.html">http://objitsu.blogspot.co.uk/2013/01/php-and-maybe-miserable-monads.html</a><br><br><br></div><div class="gmail_extra"><br><div class="gmail_quote">On 26 March 2015 at 10:26, Michael Alan Dorman <span dir="ltr"><<a href="mailto:mdorman@ironicdesign.com" target="_blank">mdorman@ironicdesign.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">Shishir Srivastava <<a href="mailto:shishir.srivastava@gmail.com">shishir.srivastava@gmail.com</a>> writes:<br>
> After reading and re-reading the haskell tutorials I don't happen to<br>
> see a very convincing or appealing reason for having these data<br>
> types.<br>
<br>
</span>To be clear: Maybe is the data *type*.  Just and Nothing are its data<br>
*constructors*.<br>
<span class=""><br>
> Can anyone please explain where Maybe and Just provide the sort of<br>
> functionality that cannot be achieved in other languages which don't<br>
> have these kind.<br>
<br>
</span>The functionality can be achieved in other languages, certainly.  The<br>
question is whether the clarity and safety is also achieved.<br>
<br>
When I see (as a totally contrived example):<br>
<br>
  fopen :: Maybe FileHandle<br>
<br>
I know that that function may not be able to return a FileHandle value<br>
all the time.  The compiler will, in fact, nag me if I do not write the<br>
code that calls it in such a way that it acknowledges that possibility.<br>
<br>
When I see:<br>
<br>
  FILE * fopen ( const char * filename, const char * mode );<br>
<br>
It is not immediately clear whether that can fail.  Sure, we can make<br>
that inference, based on what we know about filesystems, etc., but the<br>
compiler is never going to complain if I ignore the possibility.<br>
<br>
In my experience, programmers in many languages end up resorting to<br>
convention to try and work around these sorts of ambiguities.  Large<br>
projects have strategies for naming functions that try to pass along<br>
information out of band, or languages have a pervasive culture of "lint"<br>
tools that try to use heuristics to make up for what the type system<br>
doesn't make simple.<br>
<br>
That said, I know that doing Maybe sorts of things in languages that<br>
don't have, say, pattern matching, or the idea of a "failure monad",<br>
gets to be a drag very quickly---manually unwrapping things is at best<br>
awkward, having to re-wrap them just to unwrap them again in a sequence<br>
of computations quickly leads one to believe "it's just not worth<br>
it"---or you resort to exception handling, which has its own challenges<br>
to do well.<br>
<br>
Mike.<br>
_______________________________________________<br>
Beginners mailing list<br>
<a href="mailto:Beginners@haskell.org">Beginners@haskell.org</a><br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners</a><br>
</blockquote></div><br></div>