TypeCompose
From HaskellWiki
(Difference between revisions)
m (→Type composition: "O" > ":.") 
(Category:Applicative > Applicative Functor) 

(6 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:Typelevel programming]] 

== Abstract == 
== Abstract == 

−  
−  ''Warning'': The Haddock docs are out of date. I'm trying to get a working haddock 2.0 running (on my windows machine). 

'''TypeCompose''' provides some classes & instances for forms of type composition, as well as some modules that haven't found another home. 
'''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 learn about TypeCompose: 
+  Besides this wiki page, here are more ways to find out about TypeCompose: 
−  * Read [http://darcs.haskell.org/packages/TypeCompose/doc/html the Haddock docs] (with source code, additional examples, and Comment/Talk links). 
+  * Visit the [http://hackage.haskell.org/cgibin/hackagescripts/package/TypeCompose Hackage page] for library documentation and to download & install. 
−  * Get the code repository: '''<tt>darcs get http://darcs.haskell.org/packages/TypeCompose</tt>''', or 
+  * Or install with <tt>cabal install TypeCompose</tt>. 
−  * Grab a [http://darcs.haskell.org/packages/TypeCompose/dist distribution tarball]. 
+  * 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]].> 
−  * See the use of TypeCompose in [[DataDriven]]. 

−  
−  Please leave comments at the [[Talk:TypeComposeTalk page]]. 

== Type composition == 
== Type composition == 

The <hask>Control.Compose</hask> module includes 
The <hask>Control.Compose</hask> module includes 

−  * Various type compositions (unary/unary, binary/unary, etc). Most are from [http://www.soi.city.ac.uk/~ross/papers/Applicative.html Applicative Programming with Effects]. In particular, <hask>g :. f</hask> composes functors in to functors and applicative functors (AFs) into AFs. (In contrast, monads do not in general compose.) Composition makes AFbased programming simple and elegant, partly because we don't need an AF counterpart to monad transformers. 
+  * Various type compositions (unary/unary, binary/unary, etc). Most are from [http://www.soi.city.ac.uk/~ross/papers/Applicative.html Applicative Programming with Effects]. In particular, <hask>g `O` f</hask> composes functors in to functors and applicative functors (AFs) into AFs. (In contrast, monads do not in general compose.) Composition makes AFbased 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. 
* 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 <hask>Flip (>) o</hask>, for <hask>(> o)</hask>. 
* Type argument flip. Handy for cofunctors: use <hask>Flip (>) o</hask>, for <hask>(> o)</hask>. 

Line 36:  Line 34:  
=== Pair & functionlike types === 
=== Pair & functionlike types === 

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

Line 50:  Line 48:  
=== Partial values === 
=== Partial values === 

−  A monoid of partial values. See the [http://conalelliott.blogspot.com/2007/07/typeforpartialvalues.html teaser] and [http://conalelliott.blogspot.com/2007/07/implementingtypeforpartialvalues.html solution] blog 
+  A monoid of partial values. See the [http://conal.net/blog/posts/atypeforpartialvalues/ teaser] and [http://conal.net/blog/posts/implementingatypeforpartialvalues/ solution] blog 
posts. 
posts. 

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:
 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.
[edit] 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 AFbased 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
[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.
TheData.Bijection
[edit] 3.2 Pair & functionlike types
TheData.Zip
Data.Lambda
Data.Zip
zip
unzip
[]
f a > f (a,b)
f a > f (a,b)
Data.Lambda
Pair
Lambda
[edit] 3.3 References
Monads with references. Direct ripoff 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 Contextdependent monoids
Bit of an oddball also.Data.CxMonoid
mempty
mappend