### Added for loop

parent 39b612a8
 ... ... @@ -217,12 +217,39 @@ stmteval (Logical l) = logiceval l >>= \e. pure () stmteval (If l st1 st2) = logiceval l >>= \e. if e (stmteval st1) (stmteval st2) stmteval (For id st stmt) = eval st >>= \s. case s of I _ -> fail "f" SetA s -> pure (\ elem. (store id (I elem))) >>= \e.pure () stmteval (For id st stmt) = (eval st) >>= \st. case st of I _ -> fail "Cannot loop over integer" //SetA _ -> fail "f" SetA s -> (foreval id s stmt) //pure (\ elem. (store id (I (hd s)))) >>= \e.pure () //eval st >>= \s. case s of // I _ -> fail "Cannot loop over integer" // SetA s -> pure (\ elem. (store id (I (hd s)))) >>= \e.pure () //:: Sem a = Sem (State -> (Res a, State)) // SetA s -> pure (\ elem. (store id (I elem))) >>= \e.pure () foreval :: Ident [Int] Stmt -> Sem () foreval id [elem:es] stmt = (store id (I elem)) >>| (stmteval stmt) >>| (foreval id es stmt) >>| pure () //let (Sem z) = (store id (I elem)) in z foreval id [] stmt = pure () //>>= \sf. sf //foreval _ [] = // === Printing class printable a where print :: a -> String ... ... @@ -247,6 +274,12 @@ instance printable Logical where print (&&. l1 l2) = print l1 +++ "&&" +++ print l2 print (||. l1 l2) = print l1 +++ "||" +++ print l2 instance printable Stmt where print (If l stmt1 stmt2) = "if " +++ print l +++ " do " +++ print stmt1 +++ " else " +++ print stmt2 print (For i st stmt) = "for " +++ i +++ " in " +++ print st +++ " do " +++ print stmt print (Expression e) = print e print (Logical l) = print l // Set s -> pure (map (\ elem. (store id (I elem)) >>= \e.pure (stmteval stmt) ) ('Set'.toList s)) >>= \e.pure () ... ... @@ -312,13 +345,15 @@ anotherexpr2 = (New  +. ("henk" =. Elem 9) ) -. Variable "henk" //(New [4,5,6 stt :: Stmt stt = If (Variable "a" ==. (Elem 9)) (Expression ("henk" =. Elem 9)) (Expression (Elem 2)) aSet :: Expression aSet = New [0,1,9] aSet = New [0,1,8] astmt :: Stmt //astmt = If FALSE (Expression anotherexpr2) (Expression ("henk" =. Elem 10)) astmt = For "a" aSet stt //Start = let (Sem f) = (eval anotherexpr2) in f (State 'Map'.newMap) //Start = let (Sem f) = (stmteval astmt) in f (State 'Map'.newMap) Start = let (Sem f) = (stmteval astmt) in f (State 'Map'.newMap) //f = 'Set'.toList ('Set'.fromList ) // res : ((Err "Cannot add int with set"),(State Tip)) ... ... @@ -373,7 +408,7 @@ loopert prev_state prev_res prev_expr = ( (Title "Edit" @>> enterInformation [] //loopert s = enterInformation [] >>>= (\ex. let (res, stat) = (evl2 ex s) in (viewInformation [] res) ) Start world = doTasks ((loopert emptyState Nothing Nothing ) >>>= \s. viewInformation [] s) world //Start world = doTasks ((loopert emptyState Nothing Nothing ) >>>= \s. viewInformation [] s) world
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