unsafeCoerce and type aliases under type applications

Joachim Breitner mail at joachim-breitner.de
Sat Dec 3 20:39:43 CET 2011


Hi,

Am Mittwoch, den 30.11.2011, 10:51 -0200 schrieb Felipe Almeida Lessa:
> > How about using the Down/Dual/Desc/Converse/Opposite/Reverse newtype discussed
> > in another recent thread, and providing for Data.Map:
> >
> >  reverse :: Map k a -> Map (Reverse k) a
> >  reverse Tip = Tip
> >  reverse (Bin n k a l r) = Bin n (Reverse k) a (reverse r) (reverse l)
> >
> > (Arguably we also need reverse' :: Map (Reverse k) a -> Map k a. Hmm...)
> 
>   reverse' :: Map (Reverse k) a -> Map k a
>   reverse' = unsafeCoerce . reverse
> 
> Sorry, couldn't resist =).

have used unsafeCoerce to change the type inside a container to a "type"
alias in real code, but your post makes me wonder: Under what
circumstances is that safe? Is that documented somehow? Can a tool or
the compiler decide for us whether it is safe?

Thanks,
Joachim

-- 
Joachim "nomeata" Breitner
  mail at joachim-breitner.de  |  nomeata at debian.org  |  GPG: 0x4743206C
  xmpp: nomeata at joachim-breitner.de | http://www.joachim-breitner.de/

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: This is a digitally signed message part
URL: <http://www.haskell.org/pipermail/libraries/attachments/20111203/0d4eaaa4/attachment.pgp>


More information about the Libraries mailing list