| Portability | non-portable |
|---|---|
| Stability | experimental |
| Maintainer | Richard Eisenberg (eir@cis.upenn.edu) |
| Safe Haskell | None |
Language.Haskell.RoleAnnots.Check
Description
This module uses Template Haskell to check whether a declared type has the desired roles. (In versions of GHC before roles, these checks always succeed.)
- checkRoles :: Name -> [Role] -> Q [Dec]
- checkRolesB :: Name -> [Role] -> Q Exp
- data Role
- = NominalR
- | RepresentationalR
- | PhantomR
- | InferR
Documentation
checkRoles :: Name -> [Role] -> Q [Dec]Source
This function ensures that a declared type has a desired set of roles. Call it in a top-level Template Haskell splice, like this:
{-# LANGUAGE TemplateHaskell #-}
module MyMap where
import Language.Haskell.RoleAnnots
import Language.Haskell.RoleAnnots.Check
data MyMap k v = (Nominal k, Representational v) => ...
$(checkRoles ''MyMap [NominalR, RepresentationalR])
If the roles are not as desired, the checkRoles will cause a compile-
time error.
The two quote marks there are Template Haskell syntax to
quote an in-scope name. Also, due to the way Template Haskell works,
the declaration you are checking must come before the call to checkRoles.
checkRoles may be called in a separate module from where the datatype
of interest is defined. It might be useful, for example, in a testsuite.
checkRolesB :: Name -> [Role] -> Q ExpSource
This function is like checkRoles, but it can be used in a context
expecting a Bool value, like this:
rolesAreCorrect :: Bool rolesAreCorrect = $(checkRolesB ''MyMap [NominalR, RepresentationalR])
checkRolesB never produces a compile-time error.
Role is re-exported from Template Haskell for convenience.