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

Hi, Am Samstag, den 28.01.2012, 23:34 -0500 schrieb wren ng thornton:
* 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.
Even without looking at the definition of $:: and ~>, I have doubts about the existence of such a bar function (it calls foo, which needs an A, but it is not given an A and no used function produces one; albert only consumes one). Maybe you mean: foo :: A -> B -> C albert :: X -> A beth :: Y -> B carol :: C -> Z bar :: X -> Y -> Z bar = foo $:: albert ~> beth ~> carol Greetings from POPL, Joachim -- Joachim "nomeata" Breitner mail@joachim-breitner.de | nomeata@debian.org | GPG: 0x4743206C xmpp: nomeata@joachim-breitner.de | http://www.joachim-breitner.de/
participants (2)
-
Joachim Breitner
-
wren ng thornton