iTasks2.dcl 4.88 KB
Newer Older
Rinus Plasmeijer's avatar
Rinus Plasmeijer committed
1 2 3 4 5
definition module iTasks2

// (c) iTask & iData Concept and Implementation by Rinus Plasmeijer, 2006-2008 - MJP

// *********************************************************************************************************************************
Rinus Plasmeijer's avatar
Rinus Plasmeijer committed
6
// a collection of handy iTasks combinators defined in terms of the basic iTask combinators defined in module iTasks
Rinus Plasmeijer's avatar
Rinus Plasmeijer committed
7

Rinus Plasmeijer's avatar
Rinus Plasmeijer committed
8
// with Thanks to Erik Zuurbier for suggesting:  (=>>?), (-&&-?), multiAndTask
Rinus Plasmeijer's avatar
Rinus Plasmeijer committed
9 10 11 12 13 14
// *********************************************************************************************************************************

import iTasks				 

/* standard monadic combinators on iTasks:
(#>>)			:: for sequencing: bind, but no argument passed
Rinus Plasmeijer's avatar
Rinus Plasmeijer committed
15 16
return_D		:: return the value and show it in iData display format
return_VF		:: return the value and show the Html code specified
Rinus Plasmeijer's avatar
Rinus Plasmeijer committed
17
*/
Rinus Plasmeijer's avatar
Rinus Plasmeijer committed
18 19 20
(#>>) 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
21 22 23 24 25 26 27

/* 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
*/
Rinus Plasmeijer's avatar
Rinus Plasmeijer committed
28 29 30 31
(@:)   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
Rinus Plasmeijer's avatar
Rinus Plasmeijer committed
32 33 34

/* Handling recursion and loops:
repeatTask		:: repeat Task until predicate is valid
Rinus Plasmeijer's avatar
Rinus Plasmeijer committed
35
(<|)			:: repeat task (recursively) as long as predicate does not hold, and give error message otherwise
Rinus Plasmeijer's avatar
Rinus Plasmeijer committed
36 37
*/
repeatTask		:: !(a -> Task a) !(a -> Bool) a 			-> Task a		| iData a
Rinus Plasmeijer's avatar
Rinus Plasmeijer committed
38
(<|)  infixl 6 	:: !(Task a)  !(a -> (Bool, HtmlCode)) 		-> Task a 		| iData a
Rinus Plasmeijer's avatar
Rinus Plasmeijer committed
39 40

/* Choose out the tasks you want to do one forehand, labels are used to make the choice:
Rinus Plasmeijer's avatar
Rinus Plasmeijer committed
41
button 			:: return value when button pressed
Rinus Plasmeijer's avatar
Rinus Plasmeijer committed
42 43 44 45 46 47 48 49 50 51 52 53 54
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

*/
Rinus Plasmeijer's avatar
Rinus Plasmeijer committed
55
button 			:: !String 	!a 								-> Task a 		| iCreateAndPrint a
Rinus Plasmeijer's avatar
Rinus Plasmeijer committed
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
buttonTask		:: !String   !(Task a)						-> Task a 		| iCreateAndPrint a
chooseTask		:: !HtmlCode ![LabeledTask a] 				-> Task a 		| iCreateAndPrint a
chooseTaskV 	:: !HtmlCode ![LabeledTask a] 				-> Task a 		| iCreateAndPrint a

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

Rinus Plasmeijer's avatar
Rinus Plasmeijer committed
82 83 84 85
/* 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
*/
Rinus Plasmeijer's avatar
Rinus Plasmeijer committed
86 87
(=>>?) 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
Rinus Plasmeijer's avatar
Rinus Plasmeijer committed
88 89


Rinus Plasmeijer's avatar
Rinus Plasmeijer committed
90 91 92 93
/* Time and Date management:
waitForTimerTask:: Task is done when specified amount of time has passed 
*/
waitForTimerTask:: !HtmlTime								-> Task HtmlTime