[Haskell-cafe] (SPAM 3)Re: handling NULL value in database querywith Maybe (or other ...)

Ian Denhardt ian at zenhack.net
Tue Dec 18 19:56:08 UTC 2018

Quoting Paul (2018-12-18 14:28:53)

> But wait, I can get the same exception as in C/C++: fromJust Nothing
> without "if isJust..."! So, Damien is right here - no difference with
> C and Haskell is not more safe than C here - and you CAN omit checking
> and to get run time exception.

First, C doesn't give you an exception, it just tramples over memory.
The OS jumps through hoops to make it likely that it will start with
memory that will cause it to be killed before it does any real damage,
but it's still a different beast.

But if you really want that behavior could also just do:

    case x of
        Just x -> x
        Nothing -> unsafeCoerce 0

..and pattern matching doesn't save you. So yes, if you heap on enough
pedantry, you can claim that Haskell is not safer than C. But this
argument is divorced from the reality of what writing code is actually
like in these two languages. Segfaults and memory corruption are the
norm in C, and not in Haskell.

> C# 8
> [...]
> modern C++

I did say C, not C# or C++ which are entirely different languages.
Type-level nil tracking actually does give you the benefits I describe,
though it's not as nice as proper sum types more generally. I did not
say that Haskell's Maybe is the only way to achieve this.


More information about the Haskell-Cafe mailing list