#1482: unsafeCoerce# doesn't always fully coerce
----------------------------------------+-----------------------------------
Reporter: [EMAIL PROTECTED] | Owner:
Type: bug | Status: new
Priority: normal | Milestone:
Component: Compiler (Type checker) | Version: 6.6.1
Severity: normal | Resolution:
Keywords: unsafeCoerce# | Difficulty: Unknown
Os: Linux | Testcase:
Architecture: x86 |
----------------------------------------+-----------------------------------
Comment (by [EMAIL PROTECTED]):
I was going to add the comment below, but you've beat me to it.
Adding {{{-fextended-default-rules}}} definitely makes it all work, in
ways I still don't fully understand. There is no ambiguity in the
{{{forall a b. a -> b}}} explicit type signature, but the error message
suggests that the typechecker refuses to surrender the {{{Show a}}}
constraint. Am I mistaken in this interpretation?
If this is expected behavior, perhaps an error message suggesting
{{{-fextended-default-rules}}} may assist the next unwary bystander.
----
Here's what I mean by not fully coercing. This typechecks:
{{{
{-# OPTIONS_GHC -fglasgow-exts -fno-monomorphism-restriction #-}
import GHC.Prim( unsafeCoerce# )
e2 = unsafeCoerce# (shows::a -> String -> String) ::
forall a b. Show a => a -> b
}}}
However, the {{{Show a}}} constraint must be carried around all the time
which of course, severely hampers the extent of the coercion. Omitting the
constraint gives me
{{{
No instance for (Show a)
arising from use of `shows' at T.lhs:6:20-24
Possible fix: add (Show a) to the expected type of an expression
In the first argument of `unsafeCoerce#', namely
`(shows :: a -> String -> String)'
In the expression:
unsafeCoerce# (shows :: a -> String -> String) ::
forall a b. a -> b
In the definition of `e2':
e2 = unsafeCoerce# (shows :: a -> String -> String) ::
forall a b. a -> b
}}}
--
Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/1482>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler_______________________________________________
Glasgow-haskell-bugs mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs