Exposing newtype coercions to Haskell

Joachim Breitner mail at joachim-breitner.de
Tue Jul 23 11:00:10 CEST 2013


Hi,

Am Dienstag, den 23.07.2013, 09:51 +0100 schrieb Richard Eisenberg:
> A few responses:
> 
> - As Simon said, there is no great reason we don't have ~R# in Core. 
> It's just that we looked through GHC and, without newtype coercions, 
> there is no need for ~R#, so we opted not to include it. I'm still not 
> convinced we need it for newtype coercions, though. What if we have this 
> in Core?
> 
> > class NT a b = MkNT { castNT :: a -> b ; uncastNT :: b -> a }
> > NTCo:Age :: Age ~R# Int         -- see [1]
> > NTAgeInst :: NT Age Int
> > NTAgeInst = MkNT { castNT = \(a :: Age). a |> NTCo:Age ; uncastNT = \(x 
> > :: Int). x |> sym NTCo:Age }

I thought about this class definition, and it is has the nice property
that we can actually implement the methods by hand (without the
zero-cost of course), which would be a good lint-like check that we do
not generate illegal instances. The problem is that It it would not
allow
deriving instance NT a b => NT [a] [b]
as there is no way to extract the coercion that was used in the
implementation of NT a b. Hence the need to expose (to Core, not to tue
user) the coercion in the class: The cast operations do not compose
well.

Greetings,
Joachim

-- 
Joachim “nomeata” Breitner
  mail at joachim-breitner.dehttp://www.joachim-breitner.de/
  Jabber: nomeata at joachim-breitner.de  • GPG-Key: 0x4743206C
  Debian Developer: nomeata at debian.org
-------------- 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/ghc-devs/attachments/20130723/d2d3a17b/attachment.pgp>


More information about the ghc-devs mailing list