Skip to content

Instantly share code, notes, and snippets.

@matklad
Created February 10, 2013 18:44
Show Gist options
  • Save matklad/4750572 to your computer and use it in GitHub Desktop.
Save matklad/4750572 to your computer and use it in GitHub Desktop.
val p1 = Variable "x";
val p2 = TupleP [Variable "x", Variable "y"];
val p3 = ConstructorP ("Frac", Wildcard);
val p4 = ConstructorP ("Frac", ConstP 42);
val p5 = ConstructorP ("Comp", Variable "x");
val p6 = ConstructorP ("Comp", TupleP [Wildcard, Wildcard]);
val p7 = ConstructorP ("Comp", TupleP [ConstructorP ("Frac", TupleP [Wildcard, ConstP 42]),
ConstructorP ("Nat", Wildcard)]);
val pt1 = ConstructorP ("Nat", UnitP);
val p8 = ConstructorP ("Comp", TupleP [ConstructorP ("Frac", TupleP [Wildcard, ConstP 42]), pt1]);
val constructors = [("Frac", "Rational", TupleT [IntT, IntT]), ("Nat", "Rational", IntT), ("Comp", "Comp", TupleT [Datatype "Rational", Datatype "Rational"])];
get_type constructors p1 = SOME Anything;
get_type constructors p2 = SOME (TupleT [Anything, Anything]);
get_type constructors p3 = SOME (Datatype "Rational");
get_type constructors p4 = NONE;
get_type constructors p5 = SOME (Datatype "Comp");
get_type constructors p6 = SOME (Datatype "Comp");
get_type constructors p7 = SOME (Datatype "Comp");
get_type constructors p8 = NONE;
val ps1 = [TupleP[Variable("x"),Variable("y")], TupleP[Wildcard,Wildcard]];
val ps2 = [TupleP[Wildcard,Wildcard], TupleP[Wildcard,TupleP[Wildcard,Wildcard]]];
typecheck_patterns ([], ps1) = SOME (TupleT[Anything,Anything]);
typecheck_patterns ([], ps2) = SOME (TupleT[Anything,TupleT[Anything,Anything]]);
typecheck_patterns (constructors, [Wildcard,p7, Variable "x", p5, p6]) = SOME (Datatype "Comp");
typecheck_patterns ([], [TupleP [Wildcard, UnitP, ConstP 42], TupleP [ConstP 42, UnitP, Wildcard], TupleP [ConstP 42, Wildcard, UnitP]]) = NONE;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment