composition 1.0.0.1 → 1.0.1.0
raw patch · 2 files changed
+65/−21 lines, 2 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
+ Data.Composition: (.:.) :: (d -> e) -> (a -> b -> c -> d) -> a -> b -> c -> e
+ Data.Composition: (.::) :: (d -> e) -> (a -> a1 -> b -> c -> d) -> a -> a1 -> b -> c -> e
+ Data.Composition: (.::.) :: (d -> e) -> (a -> a1 -> a2 -> b -> c -> d) -> a -> a1 -> a2 -> b -> c -> e
+ Data.Composition: (.:::) :: (d -> e) -> (a -> a1 -> a2 -> a3 -> b -> c -> d) -> a -> a1 -> a2 -> a3 -> b -> c -> e
+ Data.Composition: (.:::.) :: (d -> e) -> (a -> a1 -> a2 -> a3 -> a4 -> b -> c -> d) -> a -> a1 -> a2 -> a3 -> a4 -> b -> c -> e
+ Data.Composition: (.::::) :: (d -> e) -> (a -> a1 -> a2 -> a3 -> a4 -> a5 -> b -> c -> d) -> a -> a1 -> a2 -> a3 -> a4 -> a5 -> b -> c -> e
+ Data.Composition: (.::::.) :: (d -> e) -> (a -> a1 -> a2 -> a3 -> a4 -> a5 -> a6 -> b -> c -> d) -> a -> a1 -> a2 -> a3 -> a4 -> a5 -> a6 -> b -> c -> e
+ Data.Composition: (∘) :: (b -> c) -> (a -> b) -> a -> c
+ Data.Composition: compose1 :: (b -> c) -> (a -> b) -> a -> c
Files
- composition.cabal +2/−2
- src/Data/Composition.hs +63/−19
composition.cabal view
@@ -1,5 +1,5 @@ name: composition -version: 1.0.0.1 +version: 1.0.1.0 synopsis: Combinators for unorthodox function composition license: BSD3 @@ -24,4 +24,4 @@ source-repository this type: darcs location: http://patch-tag.com/r/DanBurton/composition - tag: composition-1.0.0.1 + tag: composition-1.0.1.0
src/Data/Composition.hs view
@@ -1,27 +1,54 @@+-- | This module is for convenience and demonstrative purposes +-- more than it is for providing actual value. +-- I do not recommend that you rely on this module +-- for performance-sensitive code. +-- Because this module is not based on Prelude's (.), +-- some chances at optimization might be missed by your compiler. module Data.Composition ( - (.:), - (.*), - (.**), - (.***), - (.****), - (.*****), - (.******), - (.*******), - (.********), - compose2, - compose3, - compose4, - compose5, - compose6, - compose7, - compose8, - compose9 -) where + -- * Math + (∘) + + -- * Colons and dots + , (.:) + , (.:.) + , (.::) + , (.::.) + , (.:::) + , (.:::.) + , (.::::) + , (.::::.) + + -- * Asterisks + , (.*) + , (.**) + , (.***) + , (.****) + , (.*****) + , (.******) + , (.*******) + , (.********) + + -- * composeN + , compose1 + , compose2 + , compose3 + , compose4 + , compose5 + , compose6 + , compose7 + , compose8 + , compose9 + + ) where -- Not exported. This is defined here to remove the dependency on base (.) :: (b -> c) -> (a -> b) -> a -> c (f . g) x = f (g x) +-- | The mathematical symbol for function composition. +(∘) :: (b -> c) -> (a -> b) -> a -> c +(∘) = (.) + -- | Compose two functions. @f .: g@ is similar to @f . g@ -- except that @g@ will be fed /two/ arguments instead of one -- before handing its result to @f@. @@ -47,7 +74,7 @@ -- | Equivalent to '.:' -- -- The pattern of appending asterisks is --- more straightforward to extend to similar functions: +-- straightforward to extend to similar functions: -- (compose2 = .*, compose3 = .**, etc). -- However, @.:@ has been commonly adopted amongst Haskellers, -- and the need for compose3 and beyond is rare in practice. @@ -64,6 +91,10 @@ (.*******) = (.) . (.******) (.********) = (.) . (.*******) +-- | @composeN f g@ means give @g@ @N@ inputs +-- and then pass its result to @f@. +compose1 :: (b -> c) -> (a -> b) -> a -> c +compose1 = (.) compose2 :: (c -> d) -> (a -> b -> c) -> a -> b -> d compose2 = (.*) @@ -78,3 +109,16 @@ compose8 = (.*******) compose9 = (.********) +-- | One compact pattern for composition operators is to +-- "count the dots after the first one", +-- which begins with the common '.:', and proceeds by first +-- appending another @.@ and then replacing it with @:@ +(.:.) :: (d -> e) -> (a -> b -> c -> d) -> a -> b -> c -> e +(.:.) = (.**) + +(.::) = (.***) +(.::.) = (.****) +(.:::) = (.*****) +(.:::.) = (.******) +(.::::) = (.*******) +(.::::.) = (.********)