open Mp5common let rubric_version = "1.1" let rubric_title = "CS421 Fall 2008 MP5" (************************************************************************** * You can add new test cases by adding new elements to the following lists * Format is: * TESTARG(, , , , ..., ) * * is the number of argument that the function being tested takes. **************************************************************************) let infer tree = Mp5common.canon (Mp5common.infer Solution.gather_ty_constraints [] tree);; let infer_stu tree = Mp5common.canon (Mp5common.infer Student.gather_ty_constraints [] tree);; let infer2 gamma tree = Mp5common.canon (Mp5common.infer Solution.gather_ty_constraints gamma tree);; let infer2_stu gamma tree = Mp5common.canon (Mp5common.infer Student.gather_ty_constraints gamma tree);; let prob3 = (IfExp (ConstExp (BoolConst true), ConstExp (IntConst 1), VarExp "x")) let prob3a = (IfExp (ConstExp (BoolConst true), ConstExp (StringConst "e"),ConstExp (StringConst "f"))) let prob3fail = (IfExp (ConstExp (BoolConst true), ConstExp (IntConst 1), ConstExp (StringConst "Hello"))) let prob3b = (IfExp (ConstExp (BoolConst true), ConstExp (IntConst 1), VarExp "h")) let prob3c = (IfExp (AppExp(AppExp (BinOpExp ">", VarExp "x"), ConstExp (IntConst 1)), ConstExp (IntConst 17), VarExp "x")) let prob3e = (IfExp (ConstExp (BoolConst true), ConstExp (IntConst 1), RaiseExp(ConstExp (IntConst 6)))) let prob5 = (FunExp ("x", AppExp(AppExp(BinOpExp "+", VarExp "x"), VarExp "x"))) let prob5a = (FunExp ("k", VarExp "k")) let prob5b = (FunExp ("k", ConstExp ((StringConst "f")))) let prob3d = (IfExp (AppExp(AppExp (BinOpExp ">", VarExp "x"), ConstExp (IntConst 1)), prob5, VarExp "x")) let prob6 = (LetInExp("y", ConstExp(IntConst 5), AppExp(AppExp(BinOpExp "+", VarExp "y"), VarExp "y"))) let prob6b = (LetInExp("g", ConstExp(StringConst "Ok"), AppExp(AppExp(BinOpExp "::", VarExp "y"), VarExp "y"))) let prob6c = (LetInExp("y", ConstExp(IntConst 5), AppExp(AppExp(BinOpExp "+", VarExp "y"), VarExp "x"))) let prob7 = (LetRecInExp("ones", AppExp(AppExp(BinOpExp "::",ConstExp(IntConst 1)), VarExp "ones"), VarExp "ones")) let prob7b = (LetRecInExp("x", AppExp(AppExp(BinOpExp "+",ConstExp(IntConst 1)), VarExp "x"), VarExp "x")) let prob7c = (LetRecInExp("x", prob6 , VarExp "x")) let prob7d = (LetRecInExp("x", prob3c , VarExp "x")) let prob7e = (LetRecInExp("x", prob3d , VarExp "x")) let prob8 = (RaiseExp (IfExp (ConstExp (BoolConst true), ConstExp (IntConst 3), ConstExp (IntConst 4)))) let prob8b = (RaiseExp (IfExp (ConstExp (BoolConst true), prob5, ConstExp (IntConst 4)))) let prob8c = (RaiseExp (prob5)) let prob8d = (RaiseExp (AppExp(AppExp(BinOpExp "+.", ConstExp (FloatConst 1.2)),ConstExp (FloatConst 2.3) ))) let probExtra = (TryWithExp(AppExp (AppExp(BinOpExp "^", ConstExp (StringConst "What")), RaiseExp (ConstExp (IntConst 3))), (Some 0, ConstExp (StringConst " do you mean?")), [(None, ConstExp (StringConst " the heck?"))])) (***extra credit ***) let probExtrab = (TryWithExp(AppExp (AppExp(BinOpExp "+", ConstExp (IntConst 4)), RaiseExp (ConstExp (IntConst 3))), (Some 0, ConstExp (IntConst 1)), [(None, ConstExp (IntConst 2))])) let probExtrac = (TryWithExp( prob3e, (Some 6, ConstExp (IntConst 7)), [(None, ConstExp (StringConst " the heck?"))])) let probExtrad = (TryWithExp(AppExp (AppExp(BinOpExp "^", ConstExp (StringConst "What")), RaiseExp (ConstExp (IntConst 3))), (Some 0, ConstExp (StringConst " do you mean?")), [(None, ConstExp (StringConst " the heck?"))])) (* This list is for regular problems *) let rubric = [ (* Variables -- 5 points*) TEST2ARG_TWOFUN(1, infer2, infer2_stu, (make_env "f" (TyConst({name="->";arity=2}, [TyConst ({name="bool";arity=0}, []); fresh()]))), (VarExp "f")); TEST2ARG_TWOFUN(1, infer2, infer2_stu, (make_env "x" (TyConst({name="string";arity=0}, []))), (VarExp "x")); TEST2ARG_TWOFUN(1, infer2, infer2_stu, (make_env "x" (TyConst({name="string";arity=0}, []))), (VarExp "y")); TEST2ARG_TWOFUN(1, infer2, infer2_stu, (make_env "a" (fresh())), (VarExp "a")); TEST2ARG_TWOFUN(1, infer2, infer2_stu, (make_env "w" (TyConst({name="list";arity=1}, [TyConst ({name="string";arity=0}, [])]))), (VarExp "w")); (* Bin Ops -- 5 points *) TEST1ARG_TWOFUN(1, infer, infer_stu, (BinOpExp "::")); TEST1ARG_TWOFUN(1, infer, infer_stu, (BinOpExp "+")); TEST1ARG_TWOFUN(1, infer, infer_stu, (BinOpExp "-")); TEST1ARG_TWOFUN(1, infer, infer_stu, (BinOpExp ",")); TEST2ARG_TWOFUN(1, infer2, infer2_stu, (ins_env (make_env "*" (mk_fun_ty int_ty (mk_fun_ty int_ty int_ty))) "IntTimesOp" (mk_fun_ty int_ty (mk_fun_ty int_ty int_ty))),(BinOpExp "*")); (* If -- 10 points*) TEST2ARG_TWOFUN(1, infer2, infer2_stu, (make_env "x" (fresh())), prob3); TEST1ARG_TWOFUN(1, infer, infer_stu, (IfExp (ConstExp (BoolConst true), ConstExp (IntConst 1), ConstExp (IntConst 2)))); TEST1ARG_TWOFUN(1, infer, infer_stu, (IfExp (ConstExp (BoolConst true), ConstExp (IntConst 1), ConstExp (StringConst "Hello")))); TEST1ARG_TWOFUN(1, infer, infer_stu, (IfExp (ConstExp (NilConst), ConstExp (FloatConst 1.3), ConstExp (FloatConst 1.1)))); TEST1ARG_TWOFUN(1, infer, infer_stu, (IfExp (IfExp (ConstExp (BoolConst true), ConstExp (BoolConst true),ConstExp (BoolConst true)), ConstExp (IntConst 1), ConstExp (IntConst 2)))); TEST1ARG_TWOFUN(1, infer, infer_stu, (IfExp (ConstExp (BoolConst false), prob3a, ConstExp (StringConst "Hello")))); TEST1ARG_TWOFUN(1, infer, infer_stu, (IfExp (ConstExp (BoolConst false), ConstExp (StringConst "Hello"), prob3a))); TEST1ARG_TWOFUN(1, infer, infer_stu, (IfExp (prob3fail, ConstExp (IntConst 1), ConstExp (IntConst 2)))); TEST1ARG_TWOFUN(1, infer, infer_stu, (IfExp (ConstExp (BoolConst true), prob3fail, ConstExp (IntConst 2)))); TEST1ARG_TWOFUN(1, infer, infer_stu, (IfExp (ConstExp (BoolConst true), ConstExp (IntConst 1), prob3fail))); (* App -- 10 points *) TEST1ARG_TWOFUN(1, infer, infer_stu, (AppExp (BinOpExp "*", ConstExp (IntConst 3)))); TEST1ARG_TWOFUN(1, infer, infer_stu, (AppExp (AppExp (BinOpExp "+.", ConstExp (FloatConst 3.2)), ConstExp (FloatConst 7.2)))); TEST2ARG_TWOFUN(1, infer2, infer2_stu, (make_env "x" (mk_fun_ty int_ty (mk_fun_ty int_ty int_ty))), (AppExp (VarExp "x", ConstExp (IntConst 3)))); TEST1ARG_TWOFUN(1, infer, infer_stu, (AppExp (BinOpExp ">", (AppExp (AppExp (BinOpExp "+", ConstExp (IntConst 3)), ConstExp (IntConst 3)))))); TEST1ARG_TWOFUN(2, infer, infer_stu, (AppExp (ConstExp (IntConst 4), ConstExp (IntConst 3)))); TEST1ARG_TWOFUN(2, infer, infer_stu, (AppExp (prob5a, ConstExp (IntConst 3)))); TEST1ARG_TWOFUN(1, infer, infer_stu, (AppExp(BinOpExp "=", AppExp (prob5, ConstExp (IntConst 4))))); TEST2ARG_TWOFUN(1, infer2, infer2_stu, (make_env "r" (fresh())), (AppExp(AppExp(BinOpExp "+", VarExp "r"), VarExp "r"))); (* Fun -- 10 points *) TEST1ARG_TWOFUN(1, infer, infer_stu, prob5); TEST1ARG_TWOFUN(1, infer, infer_stu, prob5a); TEST1ARG_TWOFUN(1, infer, infer_stu, (FunExp("x", ConstExp (FloatConst 9.0)))); TEST2ARG_TWOFUN(1, infer2, infer2_stu, (make_env "x" bool_ty), prob5a); TEST1ARG_TWOFUN(1, infer, infer_stu, (FunExp("x", AppExp( BinOpExp "*", VarExp "x")))); TEST2ARG_TWOFUN(1, infer2, infer2_stu, (make_env "k" (fresh())), prob5b); TEST2ARG_TWOFUN(2, infer2, infer2_stu, (make_env "h" (fresh())), (FunExp("h", ConstExp (IntConst 7)))); TEST2ARG_TWOFUN(2, infer2, infer2_stu, (make_env "g" (fresh())), (FunExp("g", AppExp(BinOpExp "::", ConstExp (StringConst "Goodbye"))))); (* LetIn -- 10 points *) TEST1ARG_TWOFUN(1, infer, infer_stu, prob6 ); TEST1ARG_TWOFUN(1, infer, infer_stu, prob6b ); TEST1ARG_TWOFUN(2, infer, infer_stu, (LetInExp("x", ConstExp(IntConst 6), ConstExp (NilConst)))); TEST1ARG_TWOFUN(2, infer, infer_stu, (LetInExp("x", ConstExp(IntConst 10), prob5))); TEST1ARG_TWOFUN(2, infer, infer_stu, (LetInExp("h", ConstExp(IntConst 56), prob3b))); TEST1ARG_TWOFUN(2, infer, infer_stu, (LetInExp("x", ConstExp(IntConst 9), prob6c))); (* LetRecIn -- 10 points *) TEST1ARG_TWOFUN(2, infer, infer_stu, prob7 ); TEST1ARG_TWOFUN(2, infer, infer_stu, prob7b ); TEST1ARG_TWOFUN(2, infer, infer_stu, prob7c ); TEST1ARG_TWOFUN(2, infer, infer_stu, prob7d ); TEST1ARG_TWOFUN(2, infer, infer_stu, prob7e ); (* Raise -- 7 points *) TEST1ARG_TWOFUN(2, infer, infer_stu, prob8 ); TEST1ARG_TWOFUN(2, infer, infer_stu, prob8b ); TEST1ARG_TWOFUN(2, infer, infer_stu, prob8c ); TEST1ARG_TWOFUN(1, infer, infer_stu, prob8d ); ] (* This list is for extra credit problems *) let extra_rubric = [ (* TryWith -- 7 points *) TEST1ARG_TWOFUN(1, infer, infer_stu, probExtra); TEST1ARG_TWOFUN(2, infer, infer_stu, probExtrab); TEST1ARG_TWOFUN(2, infer, infer_stu, probExtrac); TEST1ARG_TWOFUN(2, infer, infer_stu, probExtrad) ]