iTasksCombinators.dcl 5.92 KB
Newer Older
Rinus Plasmeijer's avatar
Rinus Plasmeijer committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
definition module iTasksCombinators

// *********************************************************************************************************************************
// This module contains a collection of handy iTasks combinators defined in terms of the basic iTask combinators
// with Thanks to Erik Zuurbier for suggesting some of the advanced combinators
// *********************************************************************************************************************************
// iTask & iData Concept and Implementation: (c) 2006,2007,2008 - Rinus Plasmeijer
// *********************************************************************************************************************************
//
import iTasksBasicCombinators				 

/* standard monadic combinators on iTasks:
(#>>)			:: for sequencing: bind, but no argument passed
return_D		:: return the value and show it in iData display format
return_VF		:: return the value and show the Html code specified
*/
17
18
19
(#>>) infixl 1 	:: !(Task a) !(Task b) 						-> Task b		| iCreateAndPrint b
return_D		:: !a 										-> Task a		| gForm {|*|}, iCreateAndPrint a
return_VF 		:: !HtmlCode !a 		  					-> Task a		| iCreateAndPrint a
Rinus Plasmeijer's avatar
Rinus Plasmeijer committed
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38

/* Assign tasks to user with indicated id:
(@:)			:: will prompt who is waiting for task with give name
(@::)			:: as @:, a default task name is chosen as label
(@:>)			:: as @:, no prompting
(@::>)			:: as @::, no prompting
*/
(@:)   infix 3 	:: !UserId !(LabeledTask a)					-> Task a		| iData a
(@::)  infix 3 	:: !UserId !(Task a)		    			-> Task a		| iData a
(@:>)  infix 3 	:: !UserId !(LabeledTask a)					-> Task a		| iData a
(@::>) infix 3 	:: !UserId !(Task a)		    			-> Task a		| iData a

/* Handling recursion and loops:
repeatTask		:: repeat Task until predicate is valid
(<|)			:: repeat task (recursively) as long as predicate does not hold, and give error message otherwise
*/
repeatTask		:: !(a -> Task a) !(a -> Bool) a 			-> Task a		| iData a
(<|)  infixl 6 	:: !(Task a)  !(a -> (Bool, HtmlCode)) 		-> Task a 		| iData a

39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/*
Choose the tasks you want to do one forehand:
chooseTask_btn	:: choose ONE task by pressing a button, True for horizontal buttons, else vertical
chooseTask_pdm	:: as chooseTask_btn, depending on pulldownmenu item selected, Int for initial value
chooseTask_radio:: as chooseTask_btn, depending on radio item selected, Int for initial value, htmlcode for option explanation 

chooseTask_cb	:: choice N tasks out of N, order of chosen task depending on first arg
				   (initial setting, effect for all when set, explanation) for each option
*/

chooseTask_btn 	:: !HtmlCode !Bool![LabeledTask a] 			-> Task a	 	| iData a
chooseTask_pdm 	:: !HtmlCode !Int ![LabeledTask a] 			-> Task a	 	| iData a
chooseTask_radio:: !HtmlCode !Int ![(HtmlCode,LabeledTask a)]

															-> Task a		| iData a
54
55
chooseTask_cbox	:: 	!(![LabeledTask a] -> Task [a]) 
					!HtmlCode ![((!Bool,!ChoiceUpdate,!HtmlCode),LabeledTask a)]
56
57
58
															-> Task [a]		| iData a


Rinus Plasmeijer's avatar
Rinus Plasmeijer committed
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/* Choose out the tasks you want to do one forehand, labels are used to make the choice:
button 			:: return value when button pressed
buttonTask		:: do the iTask when button pressed
chooseTask		:: Choose ONE iTask from list, depending on button pressed, button horizontal displayed
chooseTaskV		:: as chooseTask, buttons vertical displayed

mchoiceTask		:: Checked tasks will be done SEQUENTIALLY
mchoiceTask2	:: as mchoiceTask, boolean used for initial setting of the checks
mchoiceTask3	:: as mchoiceTask2, function can be used to (re)set the checkboxes

mchoiceTask		:: Checked tasks can be done in INTERLEAVED
mchoiceTask2	:: as mchoiceTask, boolean used for initial setting of the checks
mchoiceTask3	:: as mchoiceTask2, function can be used to (re)set the checkboxes

*/
74
75
76
77
button 			:: !String 	!a 								-> Task a 		| iData a
buttonTask		:: !String   !(Task a)						-> Task a 		| iData a
chooseTask		:: !HtmlCode ![LabeledTask a] 				-> Task a 		| iData a
chooseTaskV 	:: !HtmlCode ![LabeledTask a] 				-> Task a 		| iData a
Rinus Plasmeijer's avatar
Rinus Plasmeijer committed
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112

mchoiceTasks 	:: !HtmlCode ![LabeledTask a] 				-> Task [a] 	| iData a
mchoiceTasks2 	:: !HtmlCode ![(!Bool,LabeledTask a)] 		-> Task [a] 	| iData a
mchoiceTasks3 	:: !HtmlCode ![((!Bool,!ChoiceUpdate,!HtmlCode),LabeledTask a)] 
															-> Task [a] 	| iData a

mchoiceAndTasks :: !HtmlCode ![LabeledTask a] 				-> Task [a]		| iData a
mchoiceAndTasks2:: !HtmlCode ![(!Bool,LabeledTask a)] 		-> Task [a] 	| iData a
mchoiceAndTasks3 :: !HtmlCode ![((!Bool,!ChoiceUpdate,!HtmlCode),LabeledTask a)] 
															-> Task [a] 	| iData a
/* Do m Tasks parallel / interleaved and FINISH as soon as SOME Task completes:
(-||-)			:: do both iTasks in any order, combined task completed as soon as any subtask is done
(-&&-)			:: do both iTasks in any order (interleaved), task completed when both done
orTasks			:: do all  iTasks in any order (interleaved), task completed as soon as any subtask is done
andTasks		:: do all  iTasks in any order (interleaved), task completed when all  done
andTasks_mu		:: assign task to indicated users, task completed when all done
*/
(-||-) infixr 3 :: !(Task a) !(Task a) 						-> Task a 		| iData a
(-&&-) infixr 4 :: !(Task a) !(Task b) 						-> Task (a,b) 	| iData a & iData b
orTasks 		:: ![LabeledTask a] 						-> (Task a) 	| iData a
andTasks		:: ![LabeledTask a]							-> Task [a]		| iData a
andTasks_mu 	:: !String ![(Int,Task a)]					-> Task [a] 	| iData a

/* convenient combinators for tasks that maybe return a result:
(=>>?)			:: as bind, but do the second task only if the first one delivers a result 
(-&&-?)			:: do both tasks in any order, task completed when all done, or one of them delivers nothing
*/
(=>>?) infixl 1 :: !(Task (Maybe a)) !(a -> Task (Maybe b)) -> Task (Maybe b) 		| iCreateAndPrint a & iCreateAndPrint b
(-&&-?)infixr 4 :: !(Task (Maybe a)) !(Task (Maybe b)) 		-> Task (Maybe (a,b)) 	| iData a & iData b


/* Time and Date management:
waitForTimerTask:: Task is done when specified amount of time has passed 
*/
waitForTimerTask:: !HtmlTime								-> Task HtmlTime