3 ms·
Of course you can do this in Haskell: http://www.haskell.org/ghc/docs/7.6.2/html/libraries/base/Unsafe-Coerce.html#v:unsafeCoerce http://www.haskell.org/ghc/do
by rmcclellan 13y ago
Of course you can do this in Haskell:
http://www.haskell.org/ghc/docs/7.6.2/html/libraries/base/Unsafe-Coerce.html#v:unsafeCoerce http://www.haskell.org/ghc/docs/7.6.2/html/libraries/base/Un...
- brandonbloom 13y agoI'll save the value judgement for another time, but I'd like to point out an important difference: As the word "unsafe" implies, these Haskell primitives forego type safety in addition to type correctness. That means you can get segfaults and other undefined behavior at runtime. Such a type error on the JVM will simply produce an exception at runtime.
- tikhonj 13y agoThis is why we have Data.Dynamic which does safe dynamic types. It almost never comes up because it turns out to be virtually useless, but that's a story for another time.
- brandonbloom 13y ago> it turns out to be virtually useless That's debatable, however Data.Dynamic is built on top of Data.Typeable, which provides a lower level runtime type safety facility. I think we can both agree Typable has lots of interesting uses.
- tel 13y agoTypeable is interesting in theory and generic traversals are a godsend, but usually I find that when I'm reaching for that particular hammer I should check twice.
- brandonbloom 13y agoI'll agree it's best to avoid fully open unions when you can, but some (super useful) things truly don't work that way. Check out http://okmij.org/ftp/Computation/monads.html#ExtensibleDS http://okmij.org/ftp/Computation/monads.html#ExtensibleDS for a cool example.
- tel 13y agoI always think of Control.Exception as the poster child for open unions.
- brandonbloom 13y agoPerfect, since exceptions are a subset of effects! Check out http://math.andrej.com/eff/ http://math.andrej.com/eff/ and its literature.
- emillon 13y agoThe difference is that Haskell does not check types at runtime like Clojure does (which is the point of strong static typing), so if the type is wrong it becomes as unsafe as C.