# TypeCompose

### From HaskellWiki

(Difference between revisions)

(Category:Type-level_programming) |
(Category:Applicative -> Applicative Functor) |

(2 intermediate revisions by one user not shown) |

## Revision as of 17:48, 9 January 2011

## Contents |

## 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:

- Visit the Hackage page for library documentation and to download & install.
- Or install with
`cabal install TypeCompose`. - Get the code repository:
`darcs get http://code.haskell.org/~conal/code/TypeCompose`.

## 2 Type composition

TheControl.Compose

- Various type compositions (unary/unary, binary/unary, etc). Most are from Applicative Programming with Effects. In particular, 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.g `O` f
- 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 , forFlip (->) o.(-> o)
- Constructor in pairs: .(f a, g a)
- Constructor in arrows/functions: .f a ~> g a

## 3 Other features

### 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.

TheData.Bijection

### 3.2 Pair- & function-like types

TheData.Zip

Data.Lambda

Data.Zip

zip

unzip

[]

f a -> f (a,b)

f a -> f (a,b)

Data.Lambda

Pair

Lambda

### 3.3 References

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

### 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.

### 3.5 Partial values

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

### 3.6 Context-dependent monoids

Bit of an oddball also.Data.CxMonoid

mempty

mappend