Portability | non-portable |
---|---|
Stability | experimental |
Maintainer | Richard Eisenberg (eir@cis.upenn.edu) |
Safe Haskell | Trustworthy |
This module provides three class constraints that can be used to make roles stricter in your datatypes. Here is a typical use case:
-- Use an association list as a map: data (Nominal k, Representational v) => Map k v = MkMap [(k,v)]
With a declaration such as this, GHC will assign correct roles to k
and v
. In versions of GHC before roles, these constraints have no
effect. You will need to make sure the language extension
-XDatatypeContexts
is enabled. This extension is enabled by default
with a default language of either Haskell98 or Haskell2010, but not
by default with a vanilla invocation of GHC. When enabling it manually,
you may also want to specify -fno-warn-deprecated-flags
, as datatype
contexts are generally a misfeature.
Note that these constraints can only make roles stricter, such as a
change from representational to nominal. Indeed, going the other way
would not be type-safe! Thus, there is no guarantee that a parameter
has the role given -- the guarantee is only that a parameter as
at least the role given. (Thus, Phantom
is always redundant and
is included only for completeness.)
To check that the roles are what you would expect, see module Language.Haskell.RoleAnnots.Check.
Documentation
class Representational a Source
Mark a type parameter as having a representational role
Representational k a |
Mark a type parameter as having a phantom role. (This is always redundant.)
Phantom k a |