
Hi all, Reading the sources of Lava (a Haskell Hardware Description DSL) I run into this definition ... unsafeCoerce :: a -> b unsafeCoerce a = unsafePerformIO $ do writeIORef ref a readIORef ref where ref = unsafePerformIO $ do newIORef undefined Is this actually equivalent to the infamous unsafeCoerce# ? Thanks in advance, Alfonso Acosta

Hi Alfonso,
Reading the sources of Lava (a Haskell Hardware Description DSL) I run into this definition ...
unsafeCoerce :: a -> b
Is this actually equivalent to the infamous unsafeCoerce# ?
Yes, see the comment in the haddock documentation for unsafePerformIO: http://haskell.org/ghc/docs/latest/html/libraries/base/Foreign.html#v%3Aunsa... Thanks Neil

On Tue, Feb 06, 2007 at 04:58:28PM +0100, Alfonso Acosta wrote:
Hi all,
Reading the sources of Lava (a Haskell Hardware Description DSL) I run into this definition ...
unsafeCoerce :: a -> b unsafeCoerce a = unsafePerformIO $ do writeIORef ref a readIORef ref where ref = unsafePerformIO $ do newIORef undefined
Is this actually equivalent to the infamous unsafeCoerce# ?
Certainly not in jhc. However, In jhc one can use unsafeCoerce__ which is provided in Jhc.Prim. An important restriction on using it in jhc that might not be obvious is that you must not 'seq' a value that has been coerced to another type. John -- John Meacham - ⑆repetae.net⑆john⑈
participants (3)
-
Alfonso Acosta
-
John Meacham
-
Neil Mitchell