StdFunc.dcl 1.24 KB
Newer Older
1 2
definition module StdFunc

Camil Staps's avatar
Camil Staps committed
3 4 5 6
/**
 * A number of general functions and functions dealing with functions.
 */

7
// ****************************************************************************************
8 9
//	Concurrent Clean Standard Library Module Version 3.0
//	Copyright 2018 Radboud University
10 11
// ****************************************************************************************

12
import StdFunctions
13 14 15

//	Some handy functions for transforming unique states:

16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
/**
 * Iterate a list of state functions.
 *
 * @param The functions
 * @param The initial state
 * @result The final state
 */
seq				:: ![.(.s -> .s)] .s -> .s

/**
 * Iterate a list of state functions with result
 *
 * @param The functions
 * @param The initial state
 * @result A list of results from the state function and the final state
 */
seqList			:: ![St .s .a] .s -> ([.a],.s)
33

34 35 36
/**
 * A function that updates a state and produces a result.
 */
37 38 39 40
:: St s a :== s -> *(a,s)

// monadic style:

41 42 43 44 45
/**
 * Monadic bind for the {{`St`}} type.
 * @type w:(St .s .a) v:(.a -> .(St .s .b)) -> u:(St .s .b), [u <= v, u <= w]
 */
(`bind`) infix 0
46 47
(`bind`) f g :== \st0 -> let (r,st1) = f st0 in g r st1

48 49 50 51
/**
 * Monadic return for the {{`St`}} type.
 * @type u:a -> u:(St .s u:a)
 */
52
return r :== \s -> (r,s)