Reference and Polymorphism

型安全性のためにOcamlは多相性を(計算の起こらない)変数の束縛のみに制限しているということを知った。
Haskellでは多相性に制限はかかっていないのでIORef(リファレンス)にunsafePerformIO(副作用)の併せ技で型安全性を壊せる。

cast :: a -> b
cast x = unsafePerformIO $ writeIORef castref x >> readIORef castref

castref :: IORef a
castref = unsafePerformIO (newIORef undefined)