[Haskell-cafe] (SPAM 3)Re: handling NULL value in database query with Maybe (or other ...)
svenpanne at gmail.com
Wed Dec 19 14:03:21 UTC 2018
Am Mi., 19. Dez. 2018 um 13:24 Uhr schrieb Paul <aquagnu at gmail.com>:
> [...] @Ian: Example with unsafeCoerce is not correct: how is
> related to Maybe/pattern matching?
I think Ian just wanted to demonstrate that it is possible to crash Haskell
programs in the same way as C programs if you really want to. OTOH, the
name "unsafeCoerce" of the function used and its type (a -> b) alone should
be very visible warning signs. ;-) Mere mortals should better forget about
its existence, but unsafeCoerce can be useful if it is wrapped correctly.
So it's a bit like a buzz saw: Quite useful if you need it, but *very*
dangerous unless you know what you're doing...
> True is that Haskell is not safe, for
> example, it has unsafe functions fromJust, etc, while pattern-matching
> is only the right way to "extract" value from Maybe (OK, also "maybe"
If you consider a language "safe" or not depends on your POV: Haskell is
safe in the sense that programs written in it (without unsafeFOO stuff and
without any FFI involved) do not segfault randomly like e.g. C programs.
fromJust uses non-exhaustive pattern matching, which raises an exception if
it encounters Nothing. This is fundametally different from e.g.
dereferencing NULL/nullptr or accessing random memory.
> Ian, by the way, how can you guarantee that Segmentation
> Fault will not happen in Haskell application? I hit even freezing of
> Haskell apps, Haskell is not a language with such assertions. May be it
> will be Rust, but Haskell - never.
Every turing complete language *will* include the possibility of
non-termination (which is what I guess you mean by "freezing), so this part
is irrelevant. But even if you ignore that, every useful programming
language on earth will give you the possibility of crashing, if you want it
or not: At one point you will need to call out to native/C land to use OS
and/or library functionality. Well, unless you want to rewrite your OS and
all libraries in your shiny new and safe language...
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Haskell-Cafe