[Haskell-beginners] Maybe and Just

Lyndon Maydwell maydwell at gmail.com
Thu Mar 26 10:27:53 UTC 2015


Hi Shishir,


Indeed, Maybe doesn't grant you additional operational functionality that
other languages lack. Most use-cases of Maybe can be matched in nearly all
mainstream languages through the use of NULL.

Maybe illustrates a desired lack of functionality in cases where it is
absent.

For example, in Java:

public static Integer myMethod(Integer a, Integer b) {
  // body}


What do we know about this method from the signature?

You would think it is a method that takes two integers and returns an
integer, but really it could take NULLs too, and could possibly return a
NULL.

Here is the equivalent Haskell signature:

myMethod :: Maybe Integer -> Maybe Integer -> IO (Maybe Integer)


We can see that Maybe allows us to replicate the possibility of NULL values
from other languages... But how is that special since other languages
already have this built-in.

Now look at the following Haskell signature:

myMethod :: Integer -> Integer -> Integer


Now what do we know about this?

We know that it takes two Integers and returns an Integer.

This is the power that comes from having Maybe as the canonical way to
represent the possibility of missing values.


On Thu, Mar 26, 2015 at 9:06 PM, Shishir Srivastava <
shishir.srivastava at gmail.com> wrote:

> Hi,
>
> After reading and re-reading the haskell tutorials I don't happen to see a
> very convincing or appealing reason for having these data types.
>
> Can anyone please explain where Maybe and Just provide the sort of
> functionality that cannot be achieved in other languages which don't have
> these kind.
>
> Thanks,
> Shishir Srivastava
>
>
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/beginners/attachments/20150326/624cc397/attachment.html>


More information about the Beginners mailing list