Safe Haskell | Safe-Inferred |
---|---|
Language | GHC2021 |
A shared-element representation of web page communication.
Synopsis
- data RepF r a = Rep {
- rep :: r
- make :: HashMap ByteString ByteString -> (HashMap ByteString ByteString, Either ByteString a)
- type Rep a = RepF Markup a
- oneRep :: Monad m => Rep a -> (Rep a -> HashMap ByteString ByteString -> m ()) -> StateT (HashMap ByteString ByteString) m (HashMap ByteString ByteString, Either ByteString a)
- newtype SharedRepF m r a = SharedRep {
- unshare :: StateT (Int, HashMap ByteString ByteString) m (RepF r a)
- type SharedRep m a = SharedRepF m Markup a
- runOnce :: Monad m => SharedRep m a -> (Markup -> HashMap ByteString ByteString -> m ()) -> m (HashMap ByteString ByteString, Either ByteString a)
- zeroState :: Monad m => SharedRep m a -> m (Markup, (HashMap ByteString ByteString, Either ByteString a))
- register :: Monad m => (ByteString -> Either ByteString a) -> (a -> ByteString) -> (ByteString -> a -> r) -> a -> SharedRepF m r a
- message :: Monad m => (ByteString -> Either ByteString a) -> (ByteString -> a -> r) -> a -> a -> SharedRepF m r a
- genName :: MonadState Int m => m ByteString
- genNamePre :: MonadState Int m => ByteString -> m ByteString
Documentation
Information contained in a web page can usually be considered to be isomorphic to a map of named values - a HashMap
. This is especially true when considering a differential of information contained in a web page. Looking at a page from the outside, it often looks like a streaming differential of a hashmap.
RepF consists of an underlying value being represented, and, given a hashmap state, a way to produce a representation of the underlying value (or error), in another domain, together with the potential to alter the hashmap state.
Rep | |
|
oneRep :: Monad m => Rep a -> (Rep a -> HashMap ByteString ByteString -> m ()) -> StateT (HashMap ByteString ByteString) m (HashMap ByteString ByteString, Either ByteString a) Source #
stateful result of one step, given a RepF
, and a monadic action.
Useful for testing and for initialising a page.
newtype SharedRepF m r a Source #
Driven by the architecture of the DOM, web page components are compositional, and tree-like, where components are often composed of other components, and values are thus shared across components.
This is sometimes referred to as "observable sharing". See data-reify as another library that reifies this (pun intended), and provided the initial inspiration for this implementation.
unshare should only be run once, which is a terrible flaw that might be fixed by linear types.
SharedRep | |
|
Instances
runOnce :: Monad m => SharedRep m a -> (Markup -> HashMap ByteString ByteString -> m ()) -> m (HashMap ByteString ByteString, Either ByteString a) Source #
Compute the initial state of a SharedRep and then run an action once (see tests).
zeroState :: Monad m => SharedRep m a -> m (Markup, (HashMap ByteString ByteString, Either ByteString a)) Source #
compute the initial state of a SharedRep (testing)
:: Monad m | |
=> (ByteString -> Either ByteString a) | Parser |
-> (a -> ByteString) | Printer |
-> (ByteString -> a -> r) | create initial object from name and initial value |
-> a | initial value |
-> SharedRepF m r a |
Create a sharedRep
:: Monad m | |
=> (ByteString -> Either ByteString a) | Parser |
-> (ByteString -> a -> r) | create initial object from name and initial value |
-> a | initial value |
-> a | default value |
-> SharedRepF m r a |
Like register
, but does not put a value into the HashMap on instantiation, consumes the value when found in the HashMap, and substitutes a default on lookup failure
genName :: MonadState Int m => m ByteString Source #
name supply for elements of a SharedRepF
genNamePre :: MonadState Int m => ByteString -> m ByteString Source #
sometimes a number doesn't work properly in html (or js???), and an alpha prefix seems to help