Illtyped generated code with unsafeCoerce#, F# and -O

Wolfgang Thaller wolfgang.thaller at gmx.net
Thu Mar 10 23:15:23 EST 2005


> g (F# f) =
>         let w     = W32# (unsafeCoerce# f)

Why does GHC even accept this code?
I think unsafeCoerce# is not intended to be able to coerce unboxed 
values.

Prelude GHC.Base> :t unsafeCoerce#
unsafeCoerce# :: forall b a. a -> b

The type variables a and b are supposed to be of kind *, and f is of 
kind #.
If we have any other function of type a -> b, for example

foo :: a -> b
foo _ = undefined

Then GHCi rejects "foo 1.0#" and prints:

<interactive>:1:4:
     Couldn't match kind `*' against `#'
     When matching the kinds of `t :: *' and `Float# :: #'
       Expected type: t
       Inferred type: Float#
     In the first argument of `foo', namely `1.0#'

Cheers,

Wolfgang




More information about the Glasgow-haskell-bugs mailing list