
Iavor Diatchki wrote:
Hello, I just wanted to point out that even the 'reasonable' uses of 'unsafeCoerce' (i.e., where a type does not appear directly in a value) may not be compatible between different implementations. Consider, for example, an implementation which turns a polymorphic program into a monomorphic one by generating different versions of functions for each of its instantiations (this is not a new idea). In particular, one also has to specialize constructor functions, which amounts to specializing datatypes. For example, 'Either@Int@Char' and 'Either@Int@Bool' become completely separate types. In addition, we may choose to add only those constructors of a specialized type that actually appear in the program. For example, 'Either@Int@Char' may have both constructors 'Left@Int@Char' and 'Righ@Int@Char', while 'Either@Int@Bool' may only have a single constructor 'Right@Int@Bool'. Now, if we use an integer tag to distinguish constructors, then by using 'unsafeCoerce' we may end up casting 'Left@Int@Char' into 'Right@Int@Bool'.
Quite right. I didn't mean to suggest that this property of unsafeCoerce should be a defined part of its behaviour across implementations, just that it currently works in GHC. Cheers, Simon