Skip to content

Ptr a is used as example of representational role but it isn't

Summary

The documentation of role annotations uses this example:

type role Ptr representational
data Ptr a = Ptr Addr#

And it says that this is the disired role of Ptr, but the source code of Ptr tells us:

-- The role of Ptr's parameter is phantom, as there is no relation between
-- the Haskell representation and whatever the user puts at the end of the
-- pointer. And phantom is useful to implement castPtr (see #9163)

-- redundant role annotation checks that this doesn't change
type role Ptr phantom
data Ptr a = Ptr Addr#
  deriving ( Eq  -- ^ @since 2.01
           , Ord -- ^ @since 2.01
           )

Proposed improvements or changes

I propose to find another example or just remove this example and skip straight to the nominal Set example.

To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information