3 import StdList, StdInt, StdChar, StdMisc, StdClass, StdString, StdFile, StdArray, Data.Maybe, Data.Map, Control.Monad, Data.Tuple, Data.Void
5 from Text import class Text, instance Text String
7 class print a :: a -> String
9 instance print Void where print _ = "Void"
10 instance print String where print s = s
11 instance print Int where print i = toString i
12 instance print [a] | print a where print l = 'Text'.join ", " (map print l)
14 class parse a :: String -> Maybe a
16 instance parse Void where parse _ = Just Void
18 instance parse String where
19 parse s = let len = size s
20 in Just (if (select s (len-1) == '\n') (s % (0, len - 2)) s) // remove newline
21 instance parse Int where
25 # s = if (select s (len-1) == '\n') (s % (0, len - 2)) s // remove newline
31 instance parse [a] | parse a where parse s = foldr (\xs list -> maybe Nothing (\e -> fmap (\l -> [e:l]) list) (parse xs)) (Just []) ('Text'.split "," s)
33 class iTasksLite a | print a & parse a & TC a
35 :: Description :== String
36 :: StoreID a :== String
37 :: Task a = // define type here
38 :: *TaskState = { console :: !*File
39 , store :: Map String Dynamic
42 store_ :: a (StoreID a) (Map String Dynamic) -> Map String Dynamic | TC a
43 store_ v sid store = put sid (dynamic v) store
45 retrieve_ :: (StoreID a) (Map String Dynamic) -> a | TC a
46 retrieve_ sid store = case get sid store of
48 Just _ = abort "type error\n"
49 Nothing = abort "empty store\n"
51 instance Functor Task where
52 fmap :: (a -> b) (Task a) -> Task b
55 instance Applicative Task where
59 (<*>) infixl 4 :: (Task (a -> b)) (Task a) -> Task b
62 instance Monad Task where
63 bind :: (Task a) (a -> Task b) -> Task b
66 eval :: (Task a) *File -> (a, *File) | iTasksLite a
67 eval (Task taskFunc) console
68 # (r, {console}) = taskFunc {store = newMap, console = console}
75 task1 = viewInformation "The answer is" 42
79 enterInformation "Enter the answer"
80 >>= viewInformation "The answer is"
87 intStore :: StoreID Int
91 task3Fail = retrieve intStore
93 intStore :: StoreID Int
103 >>= \ideas -> viewInformation "All ideas" ideas
104 >>| enterInformation "Enter new idea"
105 >>= \idea -> store (ideas ++ [toString (length ideas+1) +++ ". " +++ idea]) ideaStore
108 ideaStore :: StoreID [String]
109 ideaStore = "ideas"*/
112 # (console, world) = stdio world
113 console = console <<< "Welcome to iTasksLite" <<< "\n\n"
114 (r, console) = eval task0 console
115 console = console <<< "\n" <<< "The result of the task is " <<< print r <<< ".\n"
116 (_, world) = fclose console world