definition module StdFunctions // **************************************************************************************** // Concurrent Clean Standard Library Module Version 3.0 // Copyright 2018 Radboud University // **************************************************************************************** /** * The identity function. * * @param A value * @result The same value */ id :: !.a -> .a /** * The constant function. * * @param A value * @param Another value * @result The first value */ const :: !.a .b -> .a /** * Flip the arguments of a function. This is useful in function compositions. * * @type !.(.a -> .(.b -> .c)) .b .a -> .c * @param A function * @param The second argument to the function * @param The first argument to the function * @result The function, applied to its arguments */ flip f a b :== f b a /** * Function composition. * * @type u:(.a -> .b) u:(.c -> .a) -> u:(.c -> .b) * @param A function f * @param A function g * @result The function f o g, that is, f applied after g */ (o) infixr 9 (o) f g :== \ x -> f (g x) /** * Apply a function twice. * * @param A function f * @param A value x * @result f (f x) */ twice :: !(.a -> .a) .a -> .a /** * Apply a function as long as a property holds. * * @param A property p * @param A function f * @param An initial value x * @result x if not p x, otherwise while p f (f x) */ while :: !(a -> .Bool) (a -> a) a -> a /** * Apply a function until a property holds. * * @param A property p * @param A function f * @param An initial value x * @result x if p x, otherwise until p f (f x) */ until :: !(a -> .Bool) (a -> a) a -> a /** * Apply a function a number of times. * * @param The number of iterations n * @param The function * @param The initial value * @result The result of applying the function n times to the initial value */ iter :: !Int (.a -> .a) .a -> .a