StdFunctions.dcl 1.07 KB
Newer Older
John van Groningen's avatar
John van Groningen committed
1 2 3 4 5 6 7
definition module StdFunctions

// ****************************************************************************************
//	Concurrent Clean Standard Library Module Version 3.0
//	Copyright 2018 Radboud University
// ****************************************************************************************

Camil Staps's avatar
Camil Staps committed
8 9 10 11
//* The identity function.
id    :: !.a -> .a
//* Always returns the first argument.
const :: !.a .b -> .a
John van Groningen's avatar
John van Groningen committed
12

Camil Staps's avatar
Camil Staps committed
13 14 15 16
/**
 * Flips the arguments of a function. This is useful in function compositions.
 * @type !.(.a -> .(.b -> .c)) .b .a -> .c
 */
John van Groningen's avatar
John van Groningen committed
17 18
flip f a b :== f b a

Camil Staps's avatar
Camil Staps committed
19 20 21 22 23
/**
 * Function composition: apply `f` after `g`.
 * @type u:(.a -> .b) u:(.c -> .a) -> u:(.c -> .b)
 */
(o) infixr  9
John van Groningen's avatar
John van Groningen committed
24 25
(o) f g :== \ x -> f (g x)

Camil Staps's avatar
Camil Staps committed
26 27 28 29 30 31 32 33
//* Apply the function argument twice.
twice			:: !(.a -> .a)   .a             -> .a
//* Apply the second argument as long as the first argument holds.
while			:: !(a -> .Bool) (a -> a) 	 a 	->  a
//* Apply the second argument until the first argument holds.
until			:: !(a -> .Bool) (a -> a) 	 a 	->  a
//* Apply a function a number of times.
iter			:: !Int 		 (.a -> .a) .a	-> .a