Safe Haskell | None |
---|---|
Language | Haskell2010 |
- class UniqueDeclaration u where
- newtype UDEmpty u a = UDEmpty (u a)
- type UN u = Tagged (Cnt u) Name
- un :: UniqueDeclaration u => String -> UN u
- type UT c = Tagged (Cnt c) TypeQ
- ut :: UniqueDeclaration c => TypeQ -> UT c
- type Cnt c = c ()
- type UV = ExpQ
- monomorphic :: Type -> Bool
- type QSemQuantity = Int
- translateExtsToTH' :: Exp -> Exp
- utl :: Exp -> UV
- ud :: QuasiQuoter
- uninitialized :: Q Exp
Documentation
class UniqueDeclaration u where Source
Types that can be uniquely declared on the top level.
Like Monad
, this type class itself is not "magical". Its instances,
however, may be primitive, at least conceptually, much like IO
s Monad
instance.
Individual instances may be accompanied with certain caveats. Each
individual instance should include in its documentation what these are.
These caveats may affect surrounding code, perhaps in ways detrimental to
the program's performance or efficiency; users should thus consider
isolating "global" declarations in their own .Global
module; this is not
necessarily necessary for every instance. See the documentation of the
particular instance to see how the declarations should be declared.
The type should be monomorphic, or concrete
enough, to be type safe, so that the references
cannot be treated as multiple concreet types
(writing [Integer]
to a reference that has the
type IORef [a]
and subsequently reading [Char]
can cause the program to core dump). Ensuring
this safety is the responsibility of the
implementer of the instances of this type class;
other users of this library who do not extend this
class's functionality generally do not need to be
concerned whether the program will run correctly
at run-time, since the mistakes, which can violate
type safety, will be caught at compile-time and
the code will not build (this is, however, not
intrinsically guaranteed, much like the monad
laws: they are expected to be followed). It is
worth reiterating that instances of this class
need to be sure to not allow code with such
erroneous types to compile. For more information
about type safety, see the documentation of
unsafePerformIO
.
Example:
un "lives" =:: ([| 3 |], ut [t| Integer |] :: UT TVar)
lives
would then refer to the TVar
and would initially contain the value 3
.
:: UN u | Name of reference |
-> (UV, UT u) | Initial value, accompanied with the internal type and tagged with the unique constructor so that the correct instance can be unambiguously determined. An initial value may not make sense in some contexts; implementations of instances may choose to ignore this value, as well as the internal type and unique constructor. Implementations should document how this parameter is used. |
-> Q [Dec] | Top-level declarations for the unique declaration. At least a definition for the name and a type signature should be provided. |
Declare uniquely.
UniqueDeclaration MVar | Declaring unique The initial value is used so that the reference refers initially to that value. These preconditions apply to GHC 7.0.4 and base-0.4.3.1 and likely similar versions and implementations as well. In its low-level implementation, this instance uses If your code behaves differently when optimizations are enabled, ensure that this flag is indeed being used when the declarations are being compiled. Setting or passing this flag is NOT handled automatically by this implementation; it is the responsibility of users of this implementation to ensure that such appropriate behaviour is set when necessary. This can be accomplished by placing the line |
UniqueDeclaration MSem | Declaring unique The initial value; which is, in this case, determines the initial quantity
of the semaphore; is passed to NB: When multiple units of a resource are needed simultaneously, consider using These preconditions apply to GHC 7.0.4 and base-0.4.3.1 and likely similar versions and implementations as well. In its low-level implementation, this instance uses If your code behaves differently when optimizations are enabled, ensure that this flag is indeed being used when the declarations are being compiled. Setting or passing this flag is NOT handled automatically by this implementation; it is the responsibility of users of this implementation to ensure that such appropriate behaviour is set when necessary. This can be accomplished by placing the line |
UniqueDeclaration MSemN | Declaring unique The initial value; which is, in this case, determines the initial quantity
of the semaphore; is passed to NB: When multiple units of a resource are needed simultaneously, consider using These preconditions apply to GHC 7.0.4 and base-0.4.3.1 and likely similar versions and implementations as well. In its low-level implementation, this instance uses If your code behaves differently when optimizations are enabled, ensure that this flag is indeed being used when the declarations are being compiled. Setting or passing this flag is NOT handled automatically by this implementation; it is the responsibility of users of this implementation to ensure that such appropriate behaviour is set when necessary. This can be accomplished by placing the line |
UniqueDeclaration MSampleVar | Declaring unique The initial value is used so that the reference refers initially to that value. These preconditions apply to GHC 7.0.4 and base-0.4.3.1 and likely similar versions and implementations as well. In its low-level implementation, this instance uses If your code behaves differently when optimizations are enabled, ensure that this flag is indeed being used when the declarations are being compiled. Setting or passing this flag is NOT handled automatically by this implementation; it is the responsibility of users of this implementation to ensure that such appropriate behaviour is set when necessary. This can be accomplished by placing the line |
UniqueDeclaration TVar | Declaring unique The initial value is used so that the reference refers initially to that value. These preconditions apply to GHC 7.0.4 and base-0.4.3.1 and likely similar versions and implementations as well. In its low-level implementation, this instance uses If your code behaves differently when optimizations are enabled, ensure that this flag is indeed being used when the declarations are being compiled. Setting or passing this flag is NOT handled automatically by this implementation; it is the responsibility of users of this implementation to ensure that such appropriate behaviour is set when necessary. This can be accomplished by placing the line |
UniqueDeclaration IORef | Declaring unique The initial value is used so that the reference refers initially to that value. These preconditions apply to GHC 7.0.4 and base-0.4.3.1 and likely similar versions and implementations as well. In its low-level implementation, this instance uses If your code behaves differently when optimizations are enabled, ensure that this flag is indeed being used when the declarations are being compiled. Setting or passing this flag is NOT handled automatically by this implementation; it is the responsibility of users of this implementation to ensure that such appropriate behaviour is set when necessary. This can be accomplished by placing the line |
UniqueDeclaration TMVar | Declaring unique The initial value is used so that the reference refers initially to that value. These preconditions apply to GHC 7.0.4 and base-0.4.3.1 and likely similar versions and implementations as well. In its low-level implementation, this instance uses If your code behaves differently when optimizations are enabled, ensure that this flag is indeed being used when the declarations are being compiled. Setting or passing this flag is NOT handled automatically by this implementation; it is the responsibility of users of this implementation to ensure that such appropriate behaviour is set when necessary. This can be accomplished by placing the line |
UniqueDeclaration (Const RWLock) | Declaring unique The initial value and the internal type are ignored. NB: When multiple units of a resource are needed simultaneously, consider using These preconditions apply to GHC 7.0.4 and base-0.4.3.1 and likely similar versions and implementations as well. In its low-level implementation, this instance uses If your code behaves differently when optimizations are enabled, ensure that this flag is indeed being used when the declarations are being compiled. Setting or passing this flag is NOT handled automatically by this implementation; it is the responsibility of users of this implementation to ensure that such appropriate behaviour is set when necessary. This can be accomplished by placing the line |
UniqueDeclaration (Const QSemN) | Declaring unique The initial value; which is, in this case, determines the initial quantity
of the semaphore; is passed to NB: When multiple units of a resource are needed simultaneously, consider using These preconditions apply to GHC 7.0.4 and base-0.4.3.1 and likely similar versions and implementations as well. In its low-level implementation, this instance uses If your code behaves differently when optimizations are enabled, ensure that this flag is indeed being used when the declarations are being compiled. Setting or passing this flag is NOT handled automatically by this implementation; it is the responsibility of users of this implementation to ensure that such appropriate behaviour is set when necessary. This can be accomplished by placing the line |
UniqueDeclaration (Const QSem) | Declaring unique The initial value; which is, in this case, determines the initial quantity
of the semaphore; is passed to NB: When multiple units of a resource are needed simultaneously, consider using These preconditions apply to GHC 7.0.4 and base-0.4.3.1 and likely similar versions and implementations as well. In its low-level implementation, this instance uses If your code behaves differently when optimizations are enabled, ensure that this flag is indeed being used when the declarations are being compiled. Setting or passing this flag is NOT handled automatically by this implementation; it is the responsibility of users of this implementation to ensure that such appropriate behaviour is set when necessary. This can be accomplished by placing the line |
UniqueDeclaration (UDEmpty MVar) | Declaring unique The initial value is ignored. These preconditions apply to GHC 7.0.4 and base-0.4.3.1 and likely similar versions and implementations as well. In its low-level implementation, this instance uses If your code behaves differently when optimizations are enabled, ensure that this flag is indeed being used when the declarations are being compiled. Setting or passing this flag is NOT handled automatically by this implementation; it is the responsibility of users of this implementation to ensure that such appropriate behaviour is set when necessary. This can be accomplished by placing the line |
UniqueDeclaration (UDEmpty MSampleVar) | Declaring unique The initial value is ignored. These preconditions apply to GHC 7.0.4 and base-0.4.3.1 and likely similar versions and implementations as well. In its low-level implementation, this instance uses If your code behaves differently when optimizations are enabled, ensure that this flag is indeed being used when the declarations are being compiled. Setting or passing this flag is NOT handled automatically by this implementation; it is the responsibility of users of this implementation to ensure that such appropriate behaviour is set when necessary. This can be accomplished by placing the line |
UniqueDeclaration (UDEmpty Chan) | Declaring unique The initial value is ignored. These preconditions apply to GHC 7.0.4 and base-0.4.3.1 and likely similar versions and implementations as well. In its low-level implementation, this instance uses If your code behaves differently when optimizations are enabled, ensure that this flag is indeed being used when the declarations are being compiled. Setting or passing this flag is NOT handled automatically by this implementation; it is the responsibility of users of this implementation to ensure that such appropriate behaviour is set when necessary. This can be accomplished by placing the line |
UniqueDeclaration (UDEmpty TMVar) | Declaring unique The initial value is ignored. These preconditions apply to GHC 7.0.4 and base-0.4.3.1 and likely similar versions and implementations as well. In its low-level implementation, this instance uses If your code behaves differently when optimizations are enabled, ensure that this flag is indeed being used when the declarations are being compiled. Setting or passing this flag is NOT handled automatically by this implementation; it is the responsibility of users of this implementation to ensure that such appropriate behaviour is set when necessary. This can be accomplished by placing the line |
UniqueDeclaration (UDEmpty TChan) | Declaring unique The initial value is ignored. These preconditions apply to GHC 7.0.4 and base-0.4.3.1 and likely similar versions and implementations as well. In its low-level implementation, this instance uses If your code behaves differently when optimizations are enabled, ensure that this flag is indeed being used when the declarations are being compiled. Setting or passing this flag is NOT handled automatically by this implementation; it is the responsibility of users of this implementation to ensure that such appropriate behaviour is set when necessary. This can be accomplished by placing the line |
Identity type wrapper that indicates that the unique declaration should be "empty" by default.
UDEmpty (u a) |
UniqueDeclaration (UDEmpty MVar) | Declaring unique The initial value is ignored. These preconditions apply to GHC 7.0.4 and base-0.4.3.1 and likely similar versions and implementations as well. In its low-level implementation, this instance uses If your code behaves differently when optimizations are enabled, ensure that this flag is indeed being used when the declarations are being compiled. Setting or passing this flag is NOT handled automatically by this implementation; it is the responsibility of users of this implementation to ensure that such appropriate behaviour is set when necessary. This can be accomplished by placing the line |
UniqueDeclaration (UDEmpty MSampleVar) | Declaring unique The initial value is ignored. These preconditions apply to GHC 7.0.4 and base-0.4.3.1 and likely similar versions and implementations as well. In its low-level implementation, this instance uses If your code behaves differently when optimizations are enabled, ensure that this flag is indeed being used when the declarations are being compiled. Setting or passing this flag is NOT handled automatically by this implementation; it is the responsibility of users of this implementation to ensure that such appropriate behaviour is set when necessary. This can be accomplished by placing the line |
UniqueDeclaration (UDEmpty Chan) | Declaring unique The initial value is ignored. These preconditions apply to GHC 7.0.4 and base-0.4.3.1 and likely similar versions and implementations as well. In its low-level implementation, this instance uses If your code behaves differently when optimizations are enabled, ensure that this flag is indeed being used when the declarations are being compiled. Setting or passing this flag is NOT handled automatically by this implementation; it is the responsibility of users of this implementation to ensure that such appropriate behaviour is set when necessary. This can be accomplished by placing the line |
UniqueDeclaration (UDEmpty TMVar) | Declaring unique The initial value is ignored. These preconditions apply to GHC 7.0.4 and base-0.4.3.1 and likely similar versions and implementations as well. In its low-level implementation, this instance uses If your code behaves differently when optimizations are enabled, ensure that this flag is indeed being used when the declarations are being compiled. Setting or passing this flag is NOT handled automatically by this implementation; it is the responsibility of users of this implementation to ensure that such appropriate behaviour is set when necessary. This can be accomplished by placing the line |
UniqueDeclaration (UDEmpty TChan) | Declaring unique The initial value is ignored. These preconditions apply to GHC 7.0.4 and base-0.4.3.1 and likely similar versions and implementations as well. In its low-level implementation, this instance uses If your code behaves differently when optimizations are enabled, ensure that this flag is indeed being used when the declarations are being compiled. Setting or passing this flag is NOT handled automatically by this implementation; it is the responsibility of users of this implementation to ensure that such appropriate behaviour is set when necessary. This can be accomplished by placing the line |
un :: UniqueDeclaration u => String -> UN u Source
Construct a name for a unique declaration from a string.
ut :: UniqueDeclaration c => TypeQ -> UT c Source
Tagged unique declaration type constructor.
Transform a container with kind * -> *
into a concrete type *
by
applying the type '()' to the constructor.
Intended to be used for tagging types for unique declarations.
monomorphic :: Type -> Bool Source
Determine whether a type is polymorphic.
type QSemQuantity = Int Source
The type of values that supply an initial quantity for quantity semaphores.
translateExtsToTH' :: Exp -> Exp Source
Translate an Exts AST to a Template Haskell AST, failing when the translation result is not a Template Haskell AST.
This is defined in terms of translateExtsToTH
Apply translateExtsToTH' and lift the result into the Q
monad.
This is often used with ud
to refer to variables whose names are not required to be in scope when the quotation is expanded, in a very roundabout way.
"utl" can be thought of as a mnemonic for "unique", "translate" and "lift"; and will be updated appropriately to reflect changes to UV
.
For example, to enable self-referential recursion by referring to
variables whose names are not yet in scope, an expression quotation
[| … |]
can usually be written as utl [ud| … |]
.
ud :: QuasiQuoter Source
Alias to the QuasiQuoter
hs
, which does not require names to be in scope when the quotation is expanded, which enables self-referential recursion.
uninitialized :: Q Exp Source
An alternative to providing an initial value.
Warning: attempting to read uninitialized references can cause the program to crash.