| Copyright | (c) 2014 Edwin Westbrook Nicolas Frisby and Paul Brauner |
|---|---|
| License | BSD3 |
| Maintainer | westbrook@kestrel.edu |
| Stability | experimental |
| Portability | GHC |
| Safe Haskell | None |
| Language | Haskell2010 |
Data.Binding.Hobbits.NuMatching
Description
This module defines the typeclass , which allows
pattern-matching on the bodies of multi-bindings when their bodies
have type a. To ensure adequacy, the actual machinery of how this
works is hidden from the user, but, for any given (G)ADT NuMatching aa, the
user can use the Template Haskell function mkNuMatching to
create a NuMatching instance for a.
Synopsis
- class NuMatching a where
- mkNuMatching :: Q Type -> Q [Dec]
- data MbTypeRepr a
- isoMbTypeRepr :: NuMatching b => (a -> b) -> (b -> a) -> MbTypeRepr a
- unsafeMbTypeRepr :: MbTypeRepr a
- class NuMatchingAny1 (f :: k -> Type) where
- nuMatchingAny1Proof :: MbTypeRepr (f a)
Documentation
class NuMatching a where Source #
Instances of the class allow pattern-matching on
multi-bindings whose bodies have type NuMatching aa, i.e., on multi-bindings
of type . The structure of this class is mostly hidden
from the user; see Mb ctx amkNuMatching to see how to create instances
of the NuMatching class.
Methods
nuMatchingProof :: MbTypeRepr a Source #
Instances
mkNuMatching :: Q Type -> Q [Dec] Source #
Template Haskell function for creating NuMatching instances for (G)ADTs.
Typical usage is to include the following line in the source file for
(G)ADT T (here assumed to have two type arguments):
$(mkNuMatching [t| forall a b . T a b |])
The mkNuMatching call here will create an instance declaration for
. It is also possible to include a context in the
forall type; for example, if we define the NuMatching (T a b)ID data type as follows:
data ID a = ID a
then we can create a NuMatching instance for it like this:
$( mkNuMatching [t| NuMatching a => ID a |])
Note that, when a context is included, the Haskell parser will add
the forall a for you.
data MbTypeRepr a Source #
This type states that it is possible to replace free names with
fresh names in an object of type a. This type essentially just
captures a representation of the type a as either a Name type, a
multi-binding, a function type, or a (G)ADT. In order to be sure
that only the "right" proofs are used for (G)ADTs, however, this
type is hidden from the user, and can only be constructed with
mkNuMatching.
isoMbTypeRepr :: NuMatching b => (a -> b) -> (b -> a) -> MbTypeRepr a Source #
Build an MbTypeRepr for type a by using an isomorphism with an
already-representable type b. This is useful for building NuMatching
instances for, e.g., Integral types, by mapping to and from Integer,
without having to define instances for each one in this module.
unsafeMbTypeRepr :: MbTypeRepr a Source #
Builds an MbTypeRepr proof for use in a NuMatching instance. This proof
is unsafe because it does no renaming of fresh names, so should only be used
for types that are guaranteed not to contain any Name or Mb values.
class NuMatchingAny1 (f :: k -> Type) where Source #
Typeclass for lifting the NuMatching constraint to functors on arbitrary
kinds that do not require any constraints on their input types
Methods
nuMatchingAny1Proof :: MbTypeRepr (f a) Source #
Instances
| NuMatchingAny1 (Name :: k -> Type) Source # | |
Defined in Data.Binding.Hobbits.NuMatching Methods nuMatchingAny1Proof :: MbTypeRepr (Name a) Source # | |
| NuMatching a => NuMatchingAny1 (Constant a :: k -> Type) Source # | |
Defined in Data.Binding.Hobbits.NuMatching Methods nuMatchingAny1Proof :: MbTypeRepr (Constant a a0) Source # | |
| NuMatchingAny1 ((:~:) a :: k -> Type) Source # | |
Defined in Data.Binding.Hobbits.NuMatching Methods nuMatchingAny1Proof :: MbTypeRepr (a :~: a0) Source # | |