CommonCombinators.dcl 1.98 KB
Newer Older
1
definition module CommonCombinators
2 3 4 5
/**
* 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
*/
Rinus Plasmeijer's avatar
Rinus Plasmeijer committed
6

7
import CoreCombinators, TuningCombinators, InteractionTasks
8
import Either
9

10 11
from Types import :: User (..)

12 13 14
// A task with a label used for labeling buttons, pulldown menus, and the like
:: LabeledTask a	:== (!String,!Task a)		

15
//Task composition
16 17
(-||-) infixr 3 	:: !(Task a) !(Task a) 						-> Task a 				| iTask a
(-&&-) infixr 4 	:: !(Task a) !(Task b) 						-> Task (a,b) 			| iTask a & iTask b
18

19 20 21
anyTask				:: ![Task a]								-> Task a				| iTask a
allTasks			:: ![Task a]								-> Task [a]				| iTask a
eitherTask			:: !(Task a) !(Task b) 						-> Task (Either a b)	| iTask a & iTask b	
22

23
(||-) infixr 3		:: !(Task a) !(Task b)						-> Task b				| iTask a & iTask b
24
(-||) infixl 3		:: !(Task a) !(Task b)						-> Task a				| iTask a & iTask b
25

26 27 28
//Task composition for optional values
(>>?)	infixl 1	:: !(Task (Maybe a)) !(a -> Task (Maybe b))	-> Task (Maybe b) 		| iTask a & iTask b
(-&?&-)	infixr 4	:: !(Task (Maybe a)) !(Task (Maybe b)) 		-> Task (Maybe (a,b)) 	| iTask a & iTask b
Rinus Plasmeijer's avatar
Rinus Plasmeijer committed
29

30 31 32 33 34 35 36 37
//Post processing of results
ignoreResult		:: !(Task a) 								-> Task Void			| iTask a
transformResult 	:: !(a -> b) !(Task a)						-> Task b				| iTask a & iTask b

//Synonym for (return Void)
stop				:: Task Void


38
//Task delegation
39 40 41 42 43
class (@:) infix 3 u :: u !(LabeledTask a) -> Task a | iTask a

instance @: UserId
instance @: User
instance @: String
44

45
assignByName		:: !String !String !TaskPriority !(Maybe Timestamp) (Task a) -> Task a	| iTask a
Bas Lijnse's avatar
Bas Lijnse committed
46

Rinus Plasmeijer's avatar
Rinus Plasmeijer committed
47 48 49 50
/* 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
*/
51 52
repeatTask		:: !(a -> Task a) !(a -> Bool) a 			-> Task a					| iTask a
(<|)  infixl 6 	:: !(Task a)  !(a -> (Bool, [HtmlTag])) 	-> Task a 					| iTask a