FULE-0.3.1: Functional UI Layout Engine
Copyright(c) Paul Schnapp 2024
LicenseBSD3
MaintainerPaul Schnapp <paul.schnapp@gmail.com>
Safe HaskellSafe-Inferred
LanguageHaskell2010

FULE.Reactor

Description

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 Reactors' contents (beyond what the Component typeclass allows), providing for adding in reactants (inputs) and getting out products (outputs).

Synopsis

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 the Reactor).
  • The i type-parameter is the type of input the reaction will accept in the addReactant method.
  • The ogadt type-parameter is a higher-order type used to specify what type of output the getProduct 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.

Minimal complete definition

Nothing

Methods

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

Instances details
Reaction (Reactor i ogadt m) i ogadt Source # 
Instance details

Defined in FULE.Reactor

Methods

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 # 
Instance details

Defined in FULE.Reactor

Methods

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

Instances details
Monad m => Component (Reactor i ogadt m) m Source # 
Instance details

Defined in FULE.Reactor

Methods

requiredWidth :: Reactor i ogadt m -> m (Maybe Int) Source #

requiredHeight :: Reactor i ogadt m -> m (Maybe Int) Source #

Reaction (Reactor i ogadt m) i ogadt Source # 
Instance details

Defined in FULE.Reactor

Methods

addReactant :: i -> ogadt o -> Reactor i ogadt m -> Reactor i ogadt m Source #

getProduct :: i -> ogadt o -> Reactor i ogadt m -> Maybe o Source #

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

Instances details
NFData (Reactor' i ogadt m) Source # 
Instance details

Defined in FULE.Reactor

Methods

rnf :: Reactor' i ogadt m -> () #

Monad m => Component (Reactor' i ogadt m) m Source # 
Instance details

Defined in FULE.Reactor

Methods

requiredWidth :: Reactor' i ogadt m -> m (Maybe Int) Source #

requiredHeight :: Reactor' i ogadt m -> m (Maybe Int) Source #

Reaction (Reactor' i ogadt m) i ogadt Source # 
Instance details

Defined in FULE.Reactor

Methods

addReactant :: i -> ogadt o -> Reactor' i ogadt m -> Reactor' i ogadt m Source #

getProduct :: i -> ogadt o -> Reactor' i ogadt m -> Maybe o Source #

reactor' :: (Component r m, NFData r, Reaction r i ogadt) => r -> Reactor' i ogadt m Source #

Construct a Reactor'.