Permalink
Browse files

5-2. リスト型のデータの処理 (オプショナル) - 演習

  • Loading branch information...
1 parent c4254ce commit 2ee27b998aa830a18e68e0b6a306c193d608e524 @tomykaira committed Mar 19, 2012
Showing with 27 additions and 1 deletion.
  1. +1 −0 eval.ml
  2. +26 −1 test.ml
View
@@ -27,6 +27,7 @@ let rec eval e env =
(match (eval e1 env, eval e2 env) with
| (IntVal(n1),IntVal(n2)) -> BoolVal(n1=n2)
| (BoolVal(b1),BoolVal(b2)) -> BoolVal(b1=b2)
+ | (ListVal(l1), ListVal(l2)) -> BoolVal(l1 = l2)
| _ -> failwith "wrong value")
| Neq(e1, e2) ->
(match eval (Eq(e1, e2)) env with
View
27 test.ml
@@ -40,7 +40,32 @@ let _ =
(_te "リスト Head" (IntVal 1)
(Head (Cons(IntLit 1, Cons(IntLit 2, Cons(IntLit 3, Empty))))));
(_te "リスト Tail" (ListVal [IntVal 2; IntVal 3])
- (Tail (Cons(IntLit 1, Cons(IntLit 2, Cons(IntLit 3, Empty))))));
+ (Tail (Cons(IntLit 1, Cons(IntLit 2, Cons(IntLit 3, Empty))))));
+ (_te "ネストしたリスト"
+ (ListVal [ListVal [IntVal 1; IntVal 5];
+ ListVal [IntVal 2; IntVal 3]])
+ (Cons(Cons(IntLit 1, Cons(IntLit 5, Empty)),
+ Cons(Cons(IntLit 2, Cons(IntLit 3, Empty)), Empty))));
+ (_te "リスト比較"
+ (BoolVal false)
+ (Eq(Cons(IntLit 1, Cons(IntLit 5, Empty)),
+ Cons(IntLit 2, Cons(IntLit 3, Empty)))));
+ (_te "リスト比較"
+ (BoolVal true)
+ (Eq(Cons(IntLit 1, Cons(IntLit 5, Empty)),
+ Cons(IntLit 1, Cons(IntLit 5, Empty)))));
+ (_te "ネストしたリスト比較"
+ (BoolVal true)
+ (Eq(Cons(Cons(IntLit 1, Cons(IntLit 5, Empty)),
+ Cons(Cons(IntLit 2, Cons(IntLit 3, Empty)), Empty)),
+ Cons(Cons(IntLit 1, Cons(IntLit 5, Empty)),
+ Cons(Cons(IntLit 2, Cons(IntLit 3, Empty)), Empty)))));
+ (_te "ネストしたリスト比較"
+ (BoolVal false)
+ (Eq(Cons(Cons(IntLit 1, Cons(IntLit 5, Empty)),
+ Cons(Cons(IntLit 2, Cons(IntLit 3, Empty)), Empty)),
+ Cons(Cons(IntLit 1, Cons(IntLit 5, Empty)),
+ Cons(Cons(IntLit 2, Cons(IntLit 4, Empty)), Empty)))))
)
let _ = (

0 comments on commit 2ee27b9

Please sign in to comment.