diff --git a/StdFunc.dcl b/StdFunc.dcl index 406fe627ffa72a45a2c33047ee2967a26a1689f7..9317fd86a50a0ab606a868aa1ef4628feb19ce74 100644 --- a/StdFunc.dcl +++ b/StdFunc.dcl @@ -5,87 +5,11 @@ definition module StdFunc */ // **************************************************************************************** -// Concurrent Clean Standard Library Module Version 2.0 -// Copyright 1998 University of Nijmegen +// 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 +import StdFunctions // Some handy functions for transforming unique states: diff --git a/StdFunc.icl b/StdFunc.icl index 20c6471380e1b240aca0a135152cd1945d29d7c3..4381a9945b90bb36e9ab572a27707e72881fc223 100644 --- a/StdFunc.icl +++ b/StdFunc.icl @@ -1,42 +1,13 @@ implementation module StdFunc // **************************************************************************************** -// Concurrent Clean Standard Library Module Version 2.0 -// Copyright 1995 University of Nijmegen +// Concurrent Clean Standard Library Module Version 3.0 +// Copyright 2018 University of Nijmegen // **************************************************************************************** import StdClass, StdMisc, StdInt -id :: !.a -> .a -id x = x - -const :: !.a .b -> .a -const x y = x - -//flip::!.(.a -> .(.b -> .c)) .b .a -> .c -flip f a b :== f b a - -(o) infixr 9; // :: u:(.a -> .b) u:(.c -> .a) -> u:(.c -> .b) -(o) f g :== \ x -> f (g x) - -twice :: !(.a -> .a) .a -> .a -twice f x = f (f x) - -while :: !(a -> .Bool) (a -> a) a -> a -while p f x - | p x = while p f (f x) - = x - -until::!(a -> .Bool) (a -> a) a -> a -until p f x - | p x = x - = until p f (f x) - -iter :: !Int (.a -> .a) .a -> .a -iter 0 f x = x -iter n f x - | n > 0 = iter (n-1) f (f x) - = abort "Error: Negative index given to iter." +import StdFunctions seq :: ![.(.s -> .s)] .s -> .s seq [f:fs] arg = seq fs (f arg) diff --git a/StdFunctions.dcl b/StdFunctions.dcl index f41413c582010f0fea5264b694574eb88ce7f3a8..df922d2ff1c010cbcfe8742ccce5aa08f7674a7a 100644 --- a/StdFunctions.dcl +++ b/StdFunctions.dcl @@ -5,16 +5,80 @@ definition module StdFunctions // Copyright 2018 Radboud University // **************************************************************************************** -id :: !.a -> .a // identity function -const :: !.a .b -> .a // constant function +/** + * The identity function. + * + * @param A value + * @result The same value + */ +id :: !.a -> .a -//flip :: !.(.a -> .(.b -> .c)) .b .a -> .c // Flip arguments +/** + * 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 -(o) infixr 9 // :: u:(.a -> .b) u:(.c -> .a) -> u:(.c -> .b) // Function composition +/** + * 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) -twice :: !(.a -> .a) .a -> .a // f (f x) -while :: !(a -> .Bool) (a -> a) a -> a // while (p x) f (f x) -until :: !(a -> .Bool) (a -> a) a -> a // f (f x) until (p x) -iter :: !Int (.a -> .a) .a -> .a // f (f..(f 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