Unique as special boxing type & hidden constructors

p.k.f.holzenspies at utwente.nl p.k.f.holzenspies at utwente.nl
Fri Aug 15 10:52:47 UTC 2014

Dear all,

I'm working with Alan to instantiate everything for Data.Data, so that we can do better SYB-traversals (which should also help newcomers significantly to get into the GHC code base). Alan's looking at the AST types, I'm looking at the basic types in the compiler.

Right now, I'm looking at Unique and two questions come up:

> data Unique = MkUnique FastInt

1) As someone already commented: Is there a specific reason (other than history) that this isn't simply a newtype around an Int? If we're boxing anyway, we may as well use the default Int boxing and newtype-coerce to the specific purpose of Unique, no?

2) As a general question for GHC hacking style; what is the reason for hiding the constructors in the first place?

I understand about abstraction and there are reasons for hiding, but there's a "public GHC API" and then there are all these modules that people can import at their own peril. Nothing is guaranteed about their consistency from version to version of GHC. I don't really see the point about hiding constructors (getting in the way of automatically deriving things) and then giving extra functions like (in the case of Unique):

> getKeyFastInt (MkUnique x) = x

> mkUniqueGrimily x = MkUnique (iUnbox x)

I would propose to just make Unique a newtype for an Int and making the constructor visible.



-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/ghc-devs/attachments/20140815/d8dbd8b6/attachment.html>

More information about the ghc-devs mailing list