4 ms·
In 10 years I've had maybe 5 bugs in Haskell caused by foreign language code mutating objects under the hood, and that breaking referential transparency guarant
by dons 17y ago
In 10 years I've had maybe 5 bugs in Haskell caused by foreign language code mutating objects under the hood, and that breaking referential transparency guarantees in the Haskell code.
I would not consider this "dangerous". It's a side condition you'll need to check. The language can make this more or less easy to establish.
Typically it looks like your value is changing under the hood. It's relatively easy to debug -- since the result is so unexpected.
It's rare in Haskell. I imagine it is a bit more common in Clojure, where they rely more on Java code than Haskell does on C code.
I don't believe Clojure is an optimizing compiler -- it's not doing any optimizations based on static guarantees of referential transparency -- so that simplifies the issue. If the compiler can't guarantee purity, there's less it can do with to your code to take advantage of that, so less unusual semantics.
- swannodette 17y agoClojure isn't an optimizing compiler because the JVM is the optimizing compiler. Clojure datastructures are all declared static final which allows the JVM to work a lot of magic. I've been using Clojure for a year and half and never run into such a bug. You learn quickly that you lost all of the benefits of persistent datastructures if you're putting mutable objects into them. As a side note, Rich Hickey has been working on a project called "cells" which allows you to use even unsafe mutable Java objects with the same safe concurrency guarantees as Clojure persistent data structures.