Professional Documents
Culture Documents
Interpreters
Advanced Topics
Formal Methods Formal Methods
Formal Methods Basic Recursion / Folding Problems
assumption: Solves the goal if it is already assumed in the context.
reflexivity: Solves the goal if it is a trivial equality
trivial: Solves a variety of easy goals.
auto: Solves a greater variety of easy goals.
discriminate: Solves goal if a trivial inequality and solves any goal if the context contains false
equality
exact: Solves a goal if you know the exact proof term that proves the goal.
contradiction: Solves any goal if the context contains false or contradictory hypotheses.
intros / intro: Introduces variables appearing with forall as well as the premises (left-hand side) of
implications.
simpl: Simplifies the goal or hypotheses in the context.
unfold: Unfolds the definitions of terms.
apply: Uses implications to transform goals and hypotheses.
rewrite: Replaces a term with an equivalent term if the equivalence of the terms has already been
proven.
inversion: Deduces equalities that must be true given an equality between two constructors.
left / right: Replaces a goal consisting of a disjunction P \/ Q with just P or Q.
replace: Replace a term with a equivalent term and generates a subgoal to prove that the equality
holds.
split: Replaces a goal consisting of a conjunction P /\ Q with two subgoals P and Q.
destruct (and/or): Replaces a hypothesis P /\ Q with two hypotheses P and Q. Alternatively, if the
hypothesis is a disjunction P \/ Q, generates two subgoals, one where P holds and one
where Q holds.
destruct (case analysis): Generates a subgoal for every constructor of an inductive type. Modular Programming
induction: Generates a subgoal for every constructor of an inductive type and provides an
induction hypothesis for recursively defined constructors.
ring: Solves goals consisting of addition and multiplication operations.
tauto: Solves goals consisting of tautologies that hold in constructive logic.
field: Solves goals consisting of addition, subtraction (the additive inverse), multiplication, and
division (the multiplicative inverse).
True or False Problems
1. If f : 'a -> 'b then f is guaranteed always to return a value of type 'b. - False
2. Evaluation rules for pattern matching require evaluating each pattern pi to a value vi then
matching against vi. - False
3. In black-box testing, the implementation of a function is used to guide the development tests-F
4. Expression (e1,e2) has type t1*t2 if e1 has type t1 and e2 has type t2. - True
5. Higher-order functions are functions that return types rather than returning values - False
6. @ is tail recursive. - False; 7. None has type option. - False; 9. 3110 : int - True
8. An abstraction function maps from abstract values that do not satisfy the representation
invariant to abstract values that do satisfy the representation invariant - True
10. let f x y = x+y and let f = fun x -> fun y -> x+y are semantically equivalent. - True
11. x::x::_ is a pattern that matches any list in which the first two elements are the same. - False
12. A color modeled by r, g, b components is better represented by a variant than a record. - False
13. 11 + (Some 11) evaluates to Some 22. - False
14. A polymorphic variant type must be defined before it can be used. - False
15. If type t is abstract in signature S, then a structure with type S is not permitted to define t - F
16. A functor takes a signature as input and produces a structure as output. - False
17. A glass-box test is based on the implementation details of a module. - True
18. Every OCaml value that can appear in a .ml file is an expression. - True
19. (fun x -> e) v --> e{v/x} - True; 20. All components of a tuple must have same type - F
21. (int -> int) -> int and int -> (int -> int) are the same type. - False
22. Tail-recursive calls use O(1) stack space. - True
23. <{}, fun x -> 31 + 10> ==> fun x -> 41 - False
24. AF and RI should be documented in a module's interface. - False
25. OCaml forbids aliasing of memory locations. - False
26. Hash tables provide constant worst-case time for insert and find operations. - False
27. The Async scheduler guarantees that callbacks associated with Deferreds are executed in the
order in which those Deferreds become determined.False
28. An Ivar can be filled twice: once before it becomes determined, and once after. - False
29. In a monad, return x >>= f and f x should behave the same. - True
30. Closures can be implemented with objects, objects can be implemented with closures. - True
Type Matching Problems
1. (fun -> 42) : ’a -> int;; 2. ((=) 3) : int -> bool
3. let g x y = Some (x + y) in g : int -> int -> int option
4. let h l = List.fold right (fun x a -> x::a) l l in h : ’a list -> ’a list
5. let rec l x = l x in l : ’a ->’b;; 6. 3110 : int;; 7. List.map (fun x -> x+1) : int list -> int list
8. [[None]; [Some []]] : ’a list option list list;; 9. (() ,[]) : unit * 'a list;
10. let r x y z = y z x in r : ’a -> (’b -> ’a -> ’c) -> ’b -> ’c *);;
11. let y = 3110 in fun x -> failwith " 2024 " : ‘a -> ‘b
12. List.fold_left ( fun a x y -> (a x) - y) ( fun z -> z) [1; 2; 3] 17 : int (evaluations to 21)
More Modular Programming Problems Mutable Structure Problems
Specification Problems
Objects
Interpreter Evaluation
Extraneous Stuff