[Haskell-cafe] ANN: pointless fun

wren ng thornton wren at freegeek.org
Sun Jan 29 05:34:41 CET 2012


--------------------------------------------
-- pointless-fun 1.1.0
--------------------------------------------

The pointless-fun package offers some common point-free combinators 
(common for me at least).


--------------------------------------------
-- Long Description
--------------------------------------------

* Perhaps the most useful is that it packages up Matt Helige's classic 
multicomposition trick[1]. These combinators allow you to easily modify 
the types of a many-argument function with syntax that looks like giving 
type signatures. For example,

 > foo    :: A -> B -> C
 >
 > albert :: A -> X
 > beth   :: B -> Y
 > carol  :: C -> Z
 >
 > bar :: X -> Y -> Z
 > bar = foo $:: albert ~> beth ~> carol

I've found this to be especially helpful for defining non-derivable type 
class instances for newtypes since it both abstracts away the plumbing 
and also makes explicit what you mean.


* Other prevalent combinators include,

** (.:) for binary composition:

 > (f .: g) x y = f (g x y)
 > -- or,
 > f .: g = curry (f . uncurry g)

This is the same as the common idiom @(f .) . g@ but more easily 
extended to multiple uses, due to the fixity declaration.


** (.!) for function composition which calls the right-hand function 
eagerly; i.e., making the left-hand function strict in its first argument.

 > (f .! g) x = f $! g x

This defines the composition for the sub-category of strict Haskell 
functions. If the 'Functor' class were parameterized by the domain and 
codomain categories (e.g., a regular @Functor f@ would be @CFunctor (->) 
(->) f@ instead) then this would allow us to define functors @CFunctor 
(->) (!->) f@ where @fmap f . fmap g = fmap (f .! g)@.



[1] http://matt.immute.net/content/pointless-fun


--------------------------------------------
-- Links
--------------------------------------------

Homepage:
     http://code.haskell.org/~wren/

Hackage:
     http://hackage.haskell.org/package/pointless-fun

Darcs:
     http://community.haskell.org/~wren/pointless-fun

Haddock (Darcs version):
 
http://community.haskell.org/~wren/pointless-fun/dist/doc/html/pointless-fun

-- 
Live well,
~wren



More information about the Haskell-Cafe mailing list