module test import StdEnv import Data.Maybe import Data.Functor import qualified Data.Map as DM import iTasks import iTasks.Internal.Serialization :: Box = E.t: Box t & iTask t unBox (Box b) :== b gEq{|Box|} (Box l) (Box r) = dynamicJSONEncode l == dynamicJSONEncode r JSONEncode{|Box|} _ c = [dynamicJSONEncode c] JSONDecode{|Box|} _ [c:r] = (dynamicJSONDecode c, r) JSONDecode{|Box|} _ r = (Nothing, r) gText{|Box|} tv ma = maybe [] (gText{|*|} tv o Just) ma gEditor{|Box|} = bijectEditorValue fromBox toBox gEditor{|*|} fromBox :: Box -> Type fromBox (Box t) = fromBoxd (dynamic t) fromBoxd :: Dynamic -> Type fromBoxd (a :: ()) = Unit fromBoxd (a :: Int) = Int a fromBoxd (a :: Bool) = Bool a fromBoxd (a :: Real) = Real a fromBoxd (a :: String) = String a fromBoxd ((a, b) :: (a, b)) = Tuple (fromBoxd (dynamic a)) (fromBoxd (dynamic b)) fromBoxd ((a, b, c) :: (a, b, c)) = Tuple3 (fromBoxd (dynamic a)) (fromBoxd (dynamic b)) (fromBoxd (dynamic b)) fromBoxd (a :: Person) = Person a toBox :: Type -> Box toBox (Int a) = Box a toBox (Bool a) = Box a toBox (Real a) = Box a toBox (String a) = Box a toBox Unit = Box () toBox (Tuple l r) = case (toBox l, toBox r) of (Box l, Box r) = Box (l, r) toBox (Tuple3 l m r) = case (toBox l, toBox m, toBox r) of (Box l, Box m, Box r) = Box (l, m, r) toBox (Person p) = Box p /* gEditor{|Box|} = { Editor | genUI = \uia dp em vst->case em of Enter = (Error "enterInformation not possible for existentials (genUI)", vst) (View b=:(Box a)) = case (castEditor a).Editor.genUI uia dp (View a) vst of (Error e, vst) = (Error e, vst) (Ok (ui, es), vst) = (Ok (ui, AnnotatedState (dynamicJSONEncode (View (), uia, b)) es), vst) (Update b=:(Box a)) = case (castEditor a).Editor.genUI uia dp (Update a) vst of (Error e, vst) = (Error e, vst) (Ok (ui, es), vst) = (Ok (ui, AnnotatedState (dynamicJSONEncode (Update (), uia, b)) es), vst) , onEdit = \dp dpn es vst->case es of AnnotatedState ebox es = case dynamicJSONDecode ebox of Just (Enter, _, Box b) = case (castEditor b).Editor.onEdit dp dpn es vst of (Error e, vst) = (Error e, vst) (Ok (ui, es), vst) = (Ok (ui, AnnotatedState ebox es), vst) Just (View (), _, Box b) = case (castEditor b).Editor.onEdit dp dpn es vst of (Error e, vst) = (Error e, vst) (Ok (ui, es), vst) = (Ok (ui, AnnotatedState ebox es), vst) Just (Update (), _, Box b) = case (castEditor b).Editor.onEdit dp dpn es vst of (Error e, vst) = (Error e, vst) (Ok (ui, es), vst) = (Ok (ui, AnnotatedState ebox es), vst) Nothing = (Error "corrupt editor state in Box", vst) _ = (Error "corrupt editor state in Box", vst) , onRefresh = \dp b=:(Box nb) es vst->case es of AnnotatedState box es = case dynamicJSONDecode box of Just (View (), uia, Box _) = case (castEditor nb).Editor.genUI uia dp (View nb) vst of (Ok (ui, es), vst) = (Ok (ReplaceUI ui, AnnotatedState (dynamicJSONEncode (View (), uia, b)) es), vst) (Error e, vst) = (Error e, vst) Just (Update (), uia, Box _) = case (castEditor nb).Editor.genUI uia dp (Update nb) vst of (Ok (ui, es), vst) = (Ok (ReplaceUI ui, AnnotatedState (dynamicJSONEncode (Update (), uia, b)) es), vst) (Error e, vst) = (Error e, vst) Just (Enter, uia, Box _) = case (castEditor nb).Editor.genUI uia dp (Update nb) vst of (Ok (ui, es), vst) = (Ok (ReplaceUI ui, AnnotatedState (dynamicJSONEncode (Update (), uia, b)) es), vst) (Error e, vst) = (Error e, vst) Nothing = (Error "corrupt editor state in Box", vst) _ = (Error "corrupt editor state in Box", vst) , valueFromState = \es->case es of AnnotatedState box es = case dynamicJSONDecode box of Just (_, _, Box a) = case (castEditor a).Editor.valueFromState es of Just a = Just (Box a) Nothing = Nothing Nothing = Nothing } where castEditor :: t -> Editor t | gEditor{|*|} t castEditor _ = gEditor{|*|} */ Start w = doTasks t w //t = updateSharedInformation [] (Box 42) t = withShared (Box 42) \bs-> updateSharedInformation [] bs -|| updateSharedInformation [] bs :: Type = Int Int | Bool Bool | String String | Real Real | Unit | List [Type] | Tuple Type Type | Tuple3 Type Type Type | Person Person :: Person = {firstName :: String, lastName :: String} derive class iTask Type, Person