Personal tools

TypeCompose

From HaskellWiki

(Difference between revisions)
Jump to: navigation, search
m (renamed Pair to Zip)
(Category:Applicative -> Applicative Functor)
 
(3 intermediate revisions by 2 users not shown)
Line 1: Line 1:
 
[[Category:Composition]]
 
[[Category:Composition]]
[[Category:Applicative]]
+
[[Category:Applicative Functor]]
 
[[Category:Libraries]]
 
[[Category:Libraries]]
 
[[Category:Packages]]
 
[[Category:Packages]]
  +
[[Category:Type-level programming]]
   
 
== Abstract ==
 
== Abstract ==
Line 11: Line 12:
 
* Visit the [http://hackage.haskell.org/cgi-bin/hackage-scripts/package/TypeCompose Hackage page] for library documentation and to download & install.
 
* Visit the [http://hackage.haskell.org/cgi-bin/hackage-scripts/package/TypeCompose Hackage page] for library documentation and to download & install.
 
* Or install with <tt>cabal install TypeCompose</tt>.
 
* Or install with <tt>cabal install TypeCompose</tt>.
* Get the code repository: <tt>darcs get http://code.haskell.org/TypeCompose</tt>.
+
* Get the code repository: <tt>darcs get http://code.haskell.org/~conal/code/TypeCompose</tt>.
* See the [[TypeCompose/Versions| version history]].
+
<!--* See the [[TypeCompose/Versions| version history]].-->
   
 
== Type composition ==
 
== Type composition ==

Latest revision as of 17:48, 9 January 2011


Contents

[edit] 1 Abstract

TypeCompose provides some classes & instances for forms of type composition, as well as some modules that haven't found another home.

Besides this wiki page, here are more ways to find out about TypeCompose:

[edit] 2 Type composition

The
Control.Compose
module includes
  • Various type compositions (unary/unary, binary/unary, etc). Most are from Applicative Programming with Effects. In particular,
    g `O` f
    composes functors in to functors and applicative functors (AFs) into AFs. (In contrast, monads do not in general compose.) Composition makes AF-based programming simple and elegant, partly because we don't need an AF counterpart to monad transformers.
  • Cofunctors (contravariant functors). Great for "consumer" types, just as functors suit "producer" (container) types. There are several composition options.
  • Type argument flip. Handy for cofunctors: use
    Flip (->) o
    , for
    (-> o)
    .
  • Constructor in pairs:
    (f a, g a)
    .
  • Constructor in arrows/functions:
    f a ~> g a
    .

[edit] 3 Other features

[edit] 3.1 Composable bijections

Given all the type constructors and compositions of them, I found myself writing some pretty awkward code to wrap & unwrap through multiple layers. Composable bijections help a lot.

The
Data.Bijection
module is inspired by There and Back Again: Arrows for Invertible Programming, though done here in a less general setting.

[edit] 3.2 Pair- & function-like types

The
Data.Zip
and
Data.Lambda
patterns emerged while working on DeepArrow and Eros.
Data.Zip
generalizes
zip
and
unzip
from
[]
to other functors. It also provides variants of type
f a -> f (a,b)
and
f a -> f (a,b)
.
Data.Lambda
is similar with classes for lambda-like constructions. For example uses of
Pair
and
Lambda
, see TV and Eros.

[edit] 3.3 References

Monads with references. Direct rip-off from Global Variables in Haskell.

[edit] 3.4 Titling

For giving titles to things. I know it sounds kind of random. More useful than I first thought. Used in Phooey, TV, and Eros.

[edit] 3.5 Partial values

A monoid of partial values. See the teaser and solution blog posts.

[edit] 3.6 Context-dependent monoids

Bit of an oddball also.
Data.CxMonoid
defines a sort of meta-monoid, that can be supplied dynamically with choices of
mempty
and
mappend
. Used in Phooey (starting with version 1.3) so that layout could be a monoid but still vary in style.