
Haskell Is Exceptionally Unsafe  - johndcook
https://existentialtype.wordpress.com/2012/08/14/haskell-is-exceptionally-unsafe/
======
jmillikin
The author is complaining about two language extensions which are present in
GHC. These extensions are not part of the Haskell language, which is defined
at <http://www.haskell.org/onlinereport/haskell2010/> .

The first language extension is the function 'unsafePerformIO', defined in the
module 'System.IO.Unsafe'. It's not defined in the language spec, and is
unsafe _by design_ because it's intended for very rare and specific use cases
in performance-critical code.

The second language extension is the 'Data.Typeable' module, which defines a
mechanism of dynamic typing. The standard way to use Typeable is to let the
compiler define the instance, which is both safe and much easier to type. It's
well-known that implementing a Typeable instance manually is unsafe; for
example, see Oleg's post from 2007
<http://okmij.org/ftp/Haskell/types.html#unsound-typeable> .

Again, these are extensions to the language, implemented as experiments by a
particular compiler. A program which uses them is no longer standard Haskell.

His code does not compile when built in standard Haskell mode:

    
    
      $ ghc --make exc.hs -hide-all-packages -package haskell2010
    
      exc.hs:2:8:
          Could not find module `Data.Typeable'

~~~
sanxiyn
This is all true, but his actual point is that exception handling should not
involve Data.Typeable (or any type casting) at all. I do feel this is an
extremely obscure point that does not justify this hyperbole, but it is his
blog and he is free to decide what is important there.

~~~
jmillikin
From his post, it appears that ML handles exceptions by allowing code to add
new constructors to the 'exc' type at run-time. This is effectively
indistinguishable from the GHC implementation of dynamic typing, which uses
typeclasses.

Without some sort of dynamic type casting as used in ML or Haskell, then it's
not possible to implement an exception handler that can extract information
(such as type) about an exception. All you'd be able to determine is "some
exception was thrown".

~~~
sanxiyn
Yes, ML is adding new constructors to exn type at runtime, but this is
different from GHC implementation of dynamic typing which uses typeclasses,
because GHC does not add typeclasses at runtime. Take a look at ezyang(who is
a GHC developer)'s comments in the post.

I repeat that this is extremely obscure and probably only interesting to
people like ezyang. He is engaged in the discussion, so I guess the post was
not pointless.

------
jerf
I suspect the reason why this is being upvoted and what it actually says have
nothing to do with each other. This is a bit of an academic debate about very
precise details of exception handling, not some sort of takedown of the
Haskell hype.

In the event that you really are interested in the topic at hand, you probably
ought to read the followups on
[http://www.reddit.com/r/haskell/comments/y74vn/robert_harper...](http://www.reddit.com/r/haskell/comments/y74vn/robert_harper_haskell_is_exceptionally_unsafe/)
.

~~~
thirsteh
"Like most of Harper's articles about Haskell, this is both mostly true and an
elaborately constructed troll where it's impossible to tell whether he's
getting some lulz or merely piqued that nobody uses ML."

Indeed.

~~~
mahmud
Bob Harper is a pillar of PL research, I think the credentials of his
detractor deserve just a tiny bit more scrutiny. It's one thing to refute his
assertions, and it's something else entirely to dismiss them as "troll" or
"butthurt".

~~~
_delirium
It looks like that comment is from the author of a few popular-press PLs books
(most recently _Real World Haskell_ ), so probably knowledgeable, though not
Harper-level accomplished.

------
thirsteh
He should at least preface these kinds of posts with, or add something to the
sidebar, that reveals that he is positively and absolutely biased toward SML:
[http://en.wikipedia.org/wiki/Robert_Harper_(computer_scienti...](http://en.wikipedia.org/wiki/Robert_Harper_\(computer_scientist\))

I get an odd taste in my mouth seeing a core language contributor bashing
other languages for being "inferior," whilst attempting to appear neutral.

~~~
slurgfest
Does that affect the validity of his arguments?

I would be more sympathetic except that I am constantly seeing a certain
subset of Haskell programmers engaged in the same kind of advocacy. Should
they all disclose a conflict of interest because they like Haskell?

~~~
thirsteh
If they contributed to the Haskell type system and they are commenting on the
inferiority of the type systems of other languages, absolutely yes.

This is far from his first Haskell-bashing exercise. Take a look at the
Wikipedia page for Haskell: "Robert Harper, using Standard ML to teach
introductory programming, has given his reasons for not using Haskell. Among
these are the difficulty of reasoning about resource usage with non-strict
evaluation, that laziness complicates the definition of data types and
inductive reasoning,[49]and the "inferiority" of Haskell's class system
compared to ML's module system.[50]"

I'm not saying his arguments aren't valid. It's just curious that he's not
attacking SML with the same vitriol, and perhaps people would like to know
why.

~~~
slurgfest
I don't see how he is obligated to attack anything else with the same vitriol,
if he doesn't see the same problems with it. It seems that we might just as
well try to declare a moratorium on Haskell programmers' bashing of other
languages on the basis that those other languages are not type-safe enough.

Any time someone bashes $FAVORITE, I can just disclose to everyone that they
are a ${FAVORITE}-basher and therefore aren't speaking credibly. Hooray!

~~~
thirsteh
Surely you don't believe that SML doesn't have its own set of issues? My point
is he doesn't criticize SML in the same manner on _any_ issue, for a very good
reason: he helped design the language.

~~~
sanxiyn
I believe SML doesn't have any issue that Robert Harper cares about. It is
nearly perfect in all things Robert Harper cares about. Are you suggesting
that Robert Harper should care about more things than what he currently cares
about?

I disagree with your opinion that he doesn't criticize SML because he was
involved in the design. SML is not perfect, but Robert Harper does not
criticize SML because SML is Robert-Harper-perfect. Or nearly so.

~~~
thirsteh
What's your point?

~~~
sanxiyn
My point is that you are seeing an ulterior motive where I don't see any.

------
klodolph
Hm, I was expecting this to at least mention that exceptions in Haskell pure
code is imprecise, and you can only guarantee the exception you desire by
throwing it in the IO monad.

[http://research.microsoft.com/en-
us/um/people/simonpj/papers...](http://research.microsoft.com/en-
us/um/people/simonpj/papers/imprecise-exn.htm)

Although I'm not sure what the point is in the article: yes, if you write a
purposefully flawed instance of Typeable, you will get errors when you try to
use it. I'm not convinced that this is a demonstration that it is "unsafe",
since the flawed Typeable instance seems to cause errors in the code that
_uses_ the flawed Typeable instance, and not in other parts of the code.

~~~
slurgfest
I don't disagree. But -

> yes, if you write a purposefully flawed instance of Typeable, you will get
> errors when you try to use it.

And if you write flawed C, you will also get errors when you try to use it...
but I don't think that will get many heads nodding in the camp of static
typing zealots.

~~~
Deestan
> zealots

That word has no place in technical discussions.

~~~
slurgfest
The idea that static typing is better than any other tool for preventing bugs
is a contentious dogma, not essentially different from iPhone vs. Android
flame wars - just more intellectualized.

Don't flatter yourself that your position on a matter of hotly-argued opinion
is technical and that other positions are not technical.

------
ars
When he says "Exceptionally" does he mean "very much" or "relating to
exceptions"? Or is it a pun and he means both?

~~~
wtetzner
I think he means "relating to exceptions", but it's meant to at first make you
think "very much".

------
eedahlgren
[http://research.microsoft.com/en-
us/um/people/simonpj/papers...](http://research.microsoft.com/en-
us/um/people/simonpj/papers/safe-haskell/)

------
jcromartie
Is this a troll? I can't tell...

~~~
T_S_
The title is linkbait if not trollish. However the article is just a technical
discussion about the best way to implement exceptions in pure functional code.
He prefers the way it is done in ML.

------
peteretep
NECK BEARD VS NECK BEARD

(this article appears to have no practical implications)

~~~
paulsutter
Suddenly it's clear to me.

Haskell itself may be the greatest troll of all time. I'm dense, and it takes
me a while to "get it". But Haskell may be such an awesome troll that even the
people who implemented the language may not be in on the joke yet either.

Normally we look down on trolls. But just maybe, a troll can be so perfect
that it can be admired as a work of art. Haskell may well be that instance of
trolling elevated to an art.

