Copyright | (c) Paul Schnapp 2024 |
---|---|
License | BSD3 |
Maintainer | Paul Schnapp <paul.schnapp@gmail.com> |
Safe Haskell | Safe-Inferred |
Language | Haskell2010 |
The terminology used in this module is based on that of a chemical reaction:
- A chemical reaction is given reactants and produces products.
- Reactions are contained in reactors.
The Reactor
and (strict) Reactor'
types act as containers for
heterogeneous Component
types.
The Reaction
typeclass establishes an interface for interacting with Reactor
s'
contents (beyond what the Component
typeclass allows), providing for adding
in reactants (inputs) and getting out products (outputs).
Synopsis
- class Reaction r i ogadt where
- addReactant :: i -> ogadt o -> r -> r
- getProduct :: i -> ogadt o -> r -> Maybe o
- data Reactor i ogadt m
- reactor :: (Component r m, Reaction r i ogadt) => r -> Reactor i ogadt m
- data Reactor' i ogadt m
- reactor' :: (Component r m, NFData r, Reaction r i ogadt) => r -> Reactor' i ogadt m
Documentation
class Reaction r i ogadt where Source #
An interface for interacting with the contents of a Reactor
:
- The
r
type-parameter is the reacting type (inside theReactor
). - The
i
type-parameter is the type of input the reaction will accept in theaddReactant
method. - The
ogadt
type-parameter is a higher-order type used to specify what type of output thegetProduct
method should produce. You'll likely want to use a GADT for this type.
IMPORTANT NOTE: when implementing these methods you'll need a catchall case for any input or output cases you're not handling.
Nothing
addReactant :: i -> ogadt o -> r -> r Source #
Add a reactant (input) to the reaction.
getProduct :: i -> ogadt o -> r -> Maybe o Source #
Get a product (output) from the reaction.
Instances
Reaction (Reactor i ogadt m) i ogadt Source # | |
Defined in FULE.Reactor addReactant :: i -> ogadt o -> Reactor i ogadt m -> Reactor i ogadt m Source # getProduct :: i -> ogadt o -> Reactor i ogadt m -> Maybe o Source # | |
Reaction (Reactor' i ogadt m) i ogadt Source # | |
Defined in FULE.Reactor addReactant :: i -> ogadt o -> Reactor' i ogadt m -> Reactor' i ogadt m Source # getProduct :: i -> ogadt o -> Reactor' i ogadt m -> Maybe o Source # |
data Reactor i ogadt m Source #
A container for heterogeneous types. The contents can be interacted with
using the Reaction
typeclass.
Instances
reactor :: (Component r m, Reaction r i ogadt) => r -> Reactor i ogadt m Source #
Construct a Reactor
.
data Reactor' i ogadt m Source #
A container for heterogeneous types which is strict in its contents.
The contents can be interacted with using the Reaction
typeclass.
In addition to implementing the Component
and Reaction
typeclasses like
the Reactor
type, this type implements the NFData
typeclass from Control.DeepSeq
so evaluation of its contents can be forced.
Instances
NFData (Reactor' i ogadt m) Source # | |
Defined in FULE.Reactor | |
Monad m => Component (Reactor' i ogadt m) m Source # | |
Defined in FULE.Reactor | |
Reaction (Reactor' i ogadt m) i ogadt Source # | |
Defined in FULE.Reactor addReactant :: i -> ogadt o -> Reactor' i ogadt m -> Reactor' i ogadt m Source # getProduct :: i -> ogadt o -> Reactor' i ogadt m -> Maybe o Source # |