dataToTag# documentation

Simon Peyton Jones simonpj at microsoft.com
Wed Aug 2 08:19:26 UTC 2017


Based on memory rather that investigation:

- yes it works on any data type

- The reason that the primop dataToTag# is dangerous is that it does
  not evaluate its argument; it relies on the wrapper getTag to do
  so.    Caveat emptor!  It would be good to document this.

Simon

|  -----Original Message-----
|  From: ghc-devs [mailto:ghc-devs-bounces at haskell.org] On Behalf Of
|  David Feuer
|  Sent: 02 August 2017 03:04
|  To: ghc-devs at haskell.org
|  Subject: dataToTag# documentation
|  
|  dataToTag# is documented as getting the tag number of an enumeration,
|  which is perfectly reasonable because it's designed to support
|  deriving Enum.
|  But it *appears* to work also for non-enumeration datatypes:
|  
|  dataToTag# Nothing = 0#
|  dataToTag# (Just 3) = 1#
|  
|  Does this actually always work? If so, should that be documented, or
|  is there a realistic possibility that its behavior will change in the
|  future?
|  
|  Additionally: the documentation for dataToTag# urges readers to use
|  GHC.Base.getTag instead. But dataToTag# is exported from the "public"
|  GHC.Exts, whereas getTag is not. Should we add getTag to GHC.Exts, or
|  change the documentation for dataToTag#?
|  
|  David
|  _______________________________________________
|  ghc-devs mailing list
|  ghc-devs at haskell.org
|  https://na01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fmail.h
|  askell.org%2Fcgi-bin%2Fmailman%2Flistinfo%2Fghc-
|  devs&data=04%7C01%7Csimonpj%40microsoft.com%7C769c2a45735642edd36508d4
|  d94a767e%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C6363723612191322
|  18%7CUnknown%7CVW5rbm93bnx7IlYiOiIwLjAuMDAwMCIsIlAiOiJXaW4zMiIsIkFOIjo
|  iT3RoZXIifQ%3D%3D%7C-
|  1&sdata=585d0E3YyeKBk3DYqpvWR8ePnMR6bJ6%2Bu6dAGYk%2BNxo%3D&reserved=0


More information about the ghc-devs mailing list