Standarize GHC.Prim.Any

John Meacham john at repetae.net
Tue Aug 18 20:19:00 EDT 2009


On Mon, Aug 17, 2009 at 07:52:26PM -0400, Isaac Dupree wrote:
> Also, can/do all compilers that implement unsafeCoerce implement a safe Any?
> Hugs can do it with just "data Any = Ignored" I believe, not sure about  
> nhc, yhc or jhc...

Jhc has existentials, so that is the best way to handle this. Jhc
existentials do require an invisible type parameter to be added to the
representation so wouldn't be able to remove the extra box in general.

Jhc implements unsafeCoerce, but it is really unsafe as the type
information plays a major role in the data layout as jhc has no
'universal' run time representation of data. For instance, you
might unsafeCoerce something that was statically determined to not need
to be traversed by the garbage collector to something that the garbage
collector follows, surely resulting in a segfault or other undefined
behavior at run-time. This is the reason existentials always need to
carry around their type information, if nothing else, it potentially
guides the garbage collector. So, existentials really are the only safe
way to do this in jhc.

Really the only guarenteed safe use of unsafeCoerce in jhc is between a
newtype and its underlying representation.

        John


-- 
John Meacham - ⑆repetae.net⑆john⑈ - http://notanumber.net/


More information about the Haskell-prime mailing list