Commit 96b08362 authored by Rinus Plasmeijer's avatar Rinus Plasmeijer

*** empty log message ***


git-svn-id: https://svn.cs.ru.nl/repos/iTask-system/trunk@127 63da3aa8-80fd-4f01-9db8-e6ea747a3da2
parent 8c1353b5
......@@ -4,6 +4,8 @@ definition module iTasks2
// *********************************************************************************************************************************
// a collection of handy iTasks combinators defined in terms of primitive iTask combinators
// with Thanks to Erik Zuurbier for suggesting: (=?>), (-?&-), multiAndTask
// *********************************************************************************************************************************
import iTasks
......@@ -13,9 +15,9 @@ import iTasks
return_D :: return the value and show it in iData display format
return_VF :: return the value and show the Html code specified
*/
(#>>) 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
(#>>) 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
/* Assign tasks to user with indicated id:
(@:) :: will prompt who is waiting for task with give name
......@@ -79,6 +81,14 @@ andTasks :: ![LabeledTask a] -> Task [a] | iData a
multiAndTask :: !(LabeledTask a) -> Task Void | 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
*/
......
......@@ -8,8 +8,12 @@ import StdEnv
import iTasks
import iDataTrivial
derive gForm []
derive gUpd []
derive gForm []
derive gUpd []
derive gUpd Maybe
derive gForm Maybe
derive gPrint Maybe
derive gParse Maybe
// ******************************************************************************************************
// monads for combining iTasks
......@@ -19,6 +23,12 @@ derive gUpd []
= taska
=>> \_ -> taskb
(=>>?) infixl 1 :: !(Task (Maybe a)) !(a -> Task (Maybe b)) -> Task (Maybe b) | iCreateAndPrint a & iCreateAndPrint b
(=>>?) t1 t2
= t1
=>> \r1 -> case r1 of
Nothing -> return_V Nothing
Just r`1 -> t2 r`1
return_VF :: !HtmlCode !a -> (Task a) | iCreateAndPrint a
return_VF bodytag a = return_V a <<! bodytag
......@@ -127,6 +137,24 @@ orTasks taskCollection = newTask "orTasks" (andTasksCond "or Tasks" (\list -> le
andTasks :: ![LabeledTask a] -> (Task [a]) | iData a
andTasks taskCollection = newTask "andTasks" (andTasksCond "and Tasks" (\_ -> False) taskCollection)
(-&&-?) infixr 4 :: !(Task (Maybe a)) !(Task (Maybe b)) -> Task (Maybe (a,b)) | iData a & iData b
(-&&-?) t1 t2
= andTasksCond "Maybe Task" noNothing [("Maybe 1",left),("Maybe 2",right)]
=>> combineResult
where
left = t1 =>> \tres -> return_V (LEFT tres)
right = t2 =>> \tres -> return_V (RIGHT tres)
combineResult [LEFT (Just r1),RIGHT (Just r2)] = return_V (Just (r1,r2))
combineResult _ = return_V Nothing
noNothing [] = False
noNothing [LEFT Nothing:xs] = True
noNothing [RIGHT Nothing:xs] = True
noNothing [x:xs] = noNothing xs
multiAndTask :: !(LabeledTask a) -> Task Void | iData a
multiAndTask (label,task)
= taskId
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment