Safe use of unsafeCoerce?
duncan.coutts at worcester.oxford.ac.uk
Mon Apr 26 18:31:55 EDT 2004
On Mon, 2004-04-26 at 15:42, Alastair Reid wrote:
> > I'm after advice on whether the following example is a safe use of
> > unsafeCoerce, and if it is safe, if it's worth it.
> It looks like it is safe but it feels like using a sledgehammer to crack a
> nut ... in the presence of small children/ curious animals/ two left thumbs/
> etc. so you have to take great care that none of them are near the nut each
> time you pull that sledgehammer out.
> Given the function castFooToBar (which you tell us is safe), there's a number
> of obvious typesafe ways of writing this code, why not do so? [I accept that
> there could be some reasons I just didn't see you mention any.]
In the context of the Gtk class hierarchy, we do currently have a type
safe way of doing it (wrapBar.castForiegnPtr.unwrapFoo), but I'm trying
to eliminate the class dictionary overhead.
I'm open to other suggestions.
More information about the Glasgow-haskell-users