Haskell Is Exceptionally Unsafe
existentialtype.wordpress.com
existentialtype.wordpress.com
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'http://stackoverflow.com/questions/801785/should-i-use-ghc-h...
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".
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.
[edit]
Also, Haskell does have type-safe exceptions -- using MonadError (http://hackage.haskell.org/packages/archive/mtl/latest/doc/h...).
Actually, as far as I'm aware, IO exceptions don't see much use in practice -- they aren't considered very "Haskell-y". In fact, that's partly because of the dynamic typing aspect that this whole discussion centres around; but also because their behaviour is dependent on evaluation order, and because the possibility of an expression throwing one isn't encoded in that expression's type. None of that is really in the spirit of idiomatic Haskell.
As such, MonadError is the way exception-like behaviour tends to be handled, AFAIK.
The problem isn't even caused by Typeable itself per se, it's caused by wilfully ignoring that you're not meant to define an instance of it manually, you're meant to tell the compiler to derive one automatically. As far as I'm aware, writing your own Typeable instance causes undefined behaviour according to the very specification of the typeclass.
So, yes, Haskell's types are unsafe, if you deliberately go out of your way to subvert them. I'm left wondering... "So what?"
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... .
Indeed.
I get an odd taste in my mouth seeing a core language contributor bashing other languages for being "inferior," whilst attempting to appear neutral.
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?
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.
Any time someone bashes $FAVORITE, I can just disclose to everyone that they are a ${FAVORITE}-basher and therefore aren't speaking credibly. Hooray!
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.
His argument can be valid and still be pointless for 99% of people. Granted we all must make these decisions for ourselves, but if someone smirks and says "screw Haskell" because the exception system is unsound and then goes back to using Perl or Java, they have missed the point.
> 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?
If you see someone engage in misleading advocacy you should call them out for it. A big problem with Haskell is that it is so weird and different that new users are always blogging about how great it is. When they make a small realization they blog it, and their misconceptions come along with it. I've been using Haskell for a while, and I find it very hard to stomach it when this happens, so I don't usually follow the comments closely when I see it happen. I doubt I'm alone in that. But there's a world of difference between newbie love babble and a calculated PR stunt by a PL expert.
In this case, he points out a corner case that the Haskell community already knew about. But I, a beginner haskeller, didn't.
It's a much higher level of discourse than the typical "Haskell is {only for academics, not suitable for applications that need to handle mutable state, right-wing}" that people like to throw around.
I'm saying it wouldn't hurt his case to write a small blurb about him being one of the designers of SML in the sidebar or to use language like "when we designed SML" or "the choices we took in SML," so it doesn't appear as if it's a wholly objective critique or even subject line.
I think that is enough for a blog. In my opinion he is not trying to mislead the public. He is simply not writing for the public.
http://research.microsoft.com/en-us/um/people/simonpj/papers...
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.
> 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.
That word has no place in technical discussions.
Don't flatter yourself that your position on a matter of hotly-argued opinion is technical and that other positions are not technical.
Errors potentially in completely unrelated parts of the code. Or worse, no detectible errors at all, just silent corruption of data. You parent comment was trying to make this distinction I think, note the emphasis on "code that uses it" in the comment you're replying to.
(this article appears to have no practical implications)
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.