.
[clean-tests.git] / test.icl
index 8a75a61..822f41d 100644 (file)
--- a/test.icl
+++ b/test.icl
 module test
 
-import Debug.Trace
-import iTasks
-
-import iTasks.Extensions.DateTime
-import iTasks.UI.Layout.Minimal
-
-Start w = doTasksWithOptions opt w2 w
-where
-       t :: Task DateTime
-       t = waitForTimer 7
-       t2 :: Task Int
-       t2 = enterInformation () [] >>= viewInformation () []
-       t3 :: Task String 
-       t3 = withShared 3 \sh->
-               withTemporaryDirectory (viewInformation () [])
-               >>= viewInformation () []
-       t4 = updateInformation () [] 42
-
-       t5 = sequence [return i\\i<-[0..1000]] >>= viewInformation () []
-       t6 = waitForTimer 10
-
-       t7 :: Int -> Task Int
-       t7 i = viewInformation () [] i >>= \x->t7 (x + 1)
-
-       t8 = viewInformation () [] 1
-               >>= \_->(viewInformation () [] 2
-               >>= \_->viewInformation () [] 3
-               >>= \_->viewInformation () [] 4)
-
-       p = parallel [(Embedded, \_->waitForTimer 5)] []
-       p1 = waitForTimer 5 -||- waitForTimer 10
-       p2 = withShared 3 \sh->watch sh
-
-       w1 = withShared 0 \sds -> (watch sds @? trace_stdout) -&&- updateInformation () [] 0 -&&- updateSharedInformation () [] sds
-
-       w2 = withShared 0 \sds ->
-                     updateSharedInformation () [] sds
-               -&&- (whileUnchanged sds (viewInformation () []) @? trace_stdout)
-
-       w3 = forever (viewInformation () [] 32) @? trace_stdout
-       
-       opt args eo = Ok eo
-//     opt args eo = Ok {eo & autoLayout=False}
-
-/*
-//import StdEnv
-//import Data.Error
-//import Data.Maybe
-//import Network.IP
-//import System.Socket
-//import System.Socket.Ipv4
-////import System.Select
-//
-from Data.Map import singleton
-import Data.Map.GenJSON
-//import Data.Func
-import iTasks
-
-import iTasks.Extensions.Files
-
-//Start w = doTasks (onStartup (copyFile "/home/mrl/test.txt" "/home/mrl/test2.txt")) w
-//Start w = doTasks (onStartup (workAs SystemUser (return 42))) w 
-Start w = doTasks t w
-
-t = viewInformation () [] ()
-       >>* [OnAction ActionOk (always (return ()))
-           ,OnAction ActionQuit (always (return ()))
-               ]
-
-//Start w = doTasks t w
-//
-//t :: Task [(Int, TaskValue Int)]
-//t = parallel
-//     [(Embedded, \stl->
-//             appendTask Embedded (\_->viewInformation "Int" [] 42) stl
-//             >>! \i->set (singleton "focus" "true") (sdsFocus i (taskListEntryMeta stl))
-//             >>~ \_->viewSharedInformation "Parallel task list" []
-//                     (sdsFocus {onlyIndex=Nothing,onlyTaskId=Nothing,onlySelf=False,includeValue=True,includeProgress=True,includeAttributes=True} stl)
-//             @! 42
-//     )] []
-
-
-//import StdGeneric
-//
-//generic g a :: a
-//
-//g{|*|} = 42
-
-//Start :: *World -> (MaybeOSError String, *World)
-//Start w
-//     = case socket SocketStream w of
-//             (Error e, w) = (Error e, w)
-//             (Ok sockfd, w)
-//                     #! (merr, sockfd) = connect {ipv4_socket_port=8124,ipv4_socket_addr=Just (fromString "127.0.0.1")} sockfd
-//                     | isError merr = (liftError merr, w)
-//                     #! (merr, sockfd) = recv 128 [] sockfd
-//                     | isError merr = (merr, w)
-//                     # (Ok msg) = merr
-//                     # (merr, w) = close sockfd w
-//                     | isError merr = (liftError merr, w)
-//                     = (Ok msg, w)
-*/
+import StdEnv
+import Data.Maybe
+import Data.Functor
+import Control.Monad
+import Control.Applicative
+
+class expr v where
+       lit :: i -> v i | toString i
+       (+.) infixl 6 :: (v i) (v i) -> v i | + i
+
+instance + (v a) | expr v & + a where
+       + l r = l +. r
+
+eval :: (Maybe a) -> Maybe a
+eval x = x
+instance expr Maybe where
+       lit i = Just i
+       +. x y = (+) <$> x <*> y
+
+:: Print a =: Print String
+print :: (Print a) -> String
+print (Print a) = a
+instance expr Print where
+       lit i = Print (toString i)
+       +. (Print l) (Print r) = Print (l +++ "+" +++ r)
+
+printEval :: (A.v: v a | expr v) -> (Maybe a, String)
+//printEval f = (f, let (Print p) = f in p)
+printEval f = (eval f, print f)
+
+//Mag niet
+//Start :: (Maybe Int, String)
+//Start = printEval (lit 4 + lit 38)
+
+//Mag wel
+Start = let (Print f) = lit 4 + lit 38 in f