StdFunctions.dcl 1.9 KB
Newer Older
 John van Groningen committed Jun 27, 2019 1 2 3 4 5 6 7 ``````definition module StdFunctions // **************************************************************************************** // Concurrent Clean Standard Library Module Version 3.0 // Copyright 2018 Radboud University // **************************************************************************************** `````` John van Groningen committed Jun 27, 2019 8 9 10 11 12 13 14 ``````/** * The identity function. * * @param A value * @result The same value */ id :: !.a -> .a `````` John van Groningen committed Jun 27, 2019 15 `````` `````` John van Groningen committed Jun 27, 2019 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 ``````/** * 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 */ `````` John van Groningen committed Jun 27, 2019 34 35 ``````flip f a b :== f b a `````` John van Groningen committed Jun 27, 2019 36 37 38 39 40 41 42 43 44 ``````/** * 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 `````` John van Groningen committed Jun 27, 2019 45 46 ``````(o) f g :== \ x -> f (g x) `````` John van Groningen committed Jun 27, 2019 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 ``````/** * 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``````