TypeCompose
From HaskellWiki
Contents |
1 Abstract
TypeCompose provides some classes & instances for forms of type composition. It also includes a very simple implementation of data-driven computation.
- Read the Haddock docs (with source code, additional examples, and Comment/Talk links).
- Get the code repository: darcs get http://darcs.haskell.org/packages/TypeCompose, or
- Grab a distribution tarball.
- See the version changes.
TypeCompose is used in Phooey, a functional GUI library.
2 Type composition
For now, see the Haddock docs and source code.
3 Data-driven computation
The representation of data-driven computations is quite simple and general. They have a news publisher (news
src
news
src
type DataDrivenG news src = Compose ((,) news) src
Compose
news
src
DataDriven news src
Applicative
Compose
(,) a
instance (Applicative src) => Applicative (DataDrivenG news src) where pure a = Comp (mempty, pure a) Comp (newsf,srcf) <*> Comp (newsx, srcx) = Comp (newsf `mappend` newsx) (getf <*> getx)
mempty
mappend
DataDrivenG
src
3.1 Specializing
Specializing, introduce types of "updaters" (actions), "sinks" (consumers) of values, and "news publishers" (somewhere to register updaters to be executed when events occur).
type Updater src = src () type Sink src a = a -> Updater src type News src = Sink src (Updater src)
DataDriven
type DataDriven src = DataDrivenG (News src) src
For instance, the "Source" types used in Phooey are defined simply as
type Source = DataDriven IO
News src
src ()
f
-- Standard instance: Applicative functor applied to monoid instance Monoid a => Monoid (f a) where { mempty = pure mempty; mappend = (*>) }
()
Control.Instances
