Copyright | (c) Justus Adam, 2015 |
---|---|
License | BDS3 |
Maintainer | dev@justus.science |
Stability | experimental |
Portability | POSIX, Windows |
Safe Haskell | Safe |
Language | Haskell2010 |
Naming conventions for stuffing- and constant functions
If we follow trough with the naming conventions of stuffing- and constant functions the following rules emerge:
stuffWith1 == const0 == id stuffWith0 == const1
- stuffWith :: (α -> α -> β) -> α -> β
- stuffWith2 :: (α -> α -> β) -> α -> β
- stuffWith3 :: (α -> α -> α -> β) -> α -> β
- stuffWith4 :: (α -> α -> α -> α -> β) -> α -> β
- stuffWith5 :: (α -> α -> α -> α -> α -> β) -> α -> β
- const1 :: α -> β -> α
- const2 :: γ -> α -> β -> γ
- const3 :: δ -> α -> β -> γ -> δ
- const4 :: ε -> α -> β -> γ -> δ -> ε
- const5 :: ζ -> α -> β -> γ -> δ -> ε -> ζ
- discard :: α -> β -> β
- discard1 :: α -> β -> β
- discard2 :: α -> β -> γ -> γ
- discard3 :: α -> β -> γ -> δ -> δ
- discard4 :: α -> β -> γ -> δ -> ε -> ε
- discard5 :: α -> β -> γ -> δ -> ε -> ζ -> ζ
Stuffing functions
Functions from the stuffing family are used when a function takes several consecutive arguments of the same type.
Sometimes it is desirable to call some of these arguments with the same value and those functions here allow you to do that in the "do-not-repeat-yourself" way.
The canonical way to call this function (if all arguments are present) would be in the infix form:
function `stuffWith2` value
The naming convention is stuffWithN takes a function accepting at least N consecutive arguments of the same type and a value of that type calling the function with the provided value in all N places.
stuff3 f a == f a a a
Multiple argument stuffing can also be achieved by chaining stuffWith
.
stuffWith4 f == (stuffWith . stuffWith . stuffWith) f
stuffWith :: (α -> α -> β) -> α -> β Source
Alias for stuffWith2
stuffWith2 :: (α -> α -> β) -> α -> β Source
stuffWith3 :: (α -> α -> α -> β) -> α -> β Source
stuffWith4 :: (α -> α -> α -> α -> β) -> α -> β Source
stuffWith5 :: (α -> α -> α -> α -> α -> β) -> α -> β Source
Constant functions
Functions from the const family behave very much like const
function
from prelude. But for more arguments.
The constN function takes a value and N arguments of arbitrary type returning the value unchanged after all arguments have been supplied.
The same effect can be reached by chaining const
but does not look as good.
const3 v == (const . const . const) v
Alias for the const
function from prelude in the const function family
naming scheme.
Discard functions
Functions from the discard family behave opposite to functions from the const family.
Whereas constN will retin its first value and discard all N values, discardN wil discard the first N values, retaining the last one.