mattox@curry:~$ ocaml Objective Caml version 3.09.2 # #use "interp.ml";; val getLine : unit -> string list = # getLine ();; hello there how are you? - : string list = ["hello"; "there"; "how"; "are"; "you?"] # #use "interp.ml";; val getLine : unit -> string list = type exp = IntExp of int | VarExp of string | FunExp of string * exp | AppExp of exp * exp | PlusExp of exp * exp val show : exp -> string = val p1 : exp = IntExp 3 val p2 : exp = VarExp "x" val p3 : exp = AppExp (FunExp ("x", VarExp "y"), IntExp 7) # show p1;; - : string = "3" # show p2;; - : string = "x" # show p3;; - : string = "( \\ x . y 7 )" # print_string (show p3);; ( \ x . y 7 )- : unit = () # #use "interp.ml";; val getLine : unit -> string list = type exp = IntExp of int | VarExp of string | FunExp of string * exp | AppExp of exp * exp | PlusExp of exp * exp val show : exp -> string = val p1 : exp = IntExp 3 val p2 : exp = VarExp "x" val p3 : exp = AppExp (FunExp ("x", VarExp "y"), IntExp 7) # show p3;; - : string = "( \\ x . y 7 )\n" # print_string (show p3);; ( \ x . y 7 ) - : unit = () # #use "interp.ml";; val getLine : unit -> string list = type exp = IntExp of int | VarExp of string | FunExp of string * exp | AppExp of exp * exp | PlusExp of exp * exp val show : exp -> string = val p1 : exp = IntExp 3 val p2 : exp = VarExp "x" val p3 : exp = AppExp (FunExp ("x", VarExp "y"), IntExp 7) File "interp.ml", line 33, characters 2-121: Warning P: this pattern-matching is not exhaustive. Here is an example of a value that is not matched: [] val getL : string list -> exp * string list = # getL (getLine());; x - : exp * string list = (VarExp "x", []) # getL (getLine());; y - : exp * string list = (VarExp "y", []) # getL (getLine());; foo Exception: Match_failure ("interp.ml", 33, 2). # Str.match;; Characters 4-9: Str.match;; ^^^^^ Syntax error # open Str;; # match;; Characters 5-7: match;; ^^ Syntax error # regexp "[0-9]+";; - : Str.regexp = # #use "interp.ml";; val getLine : unit -> string list = type exp = IntExp of int | VarExp of string | FunExp of string * exp | AppExp of exp * exp | PlusExp of exp * exp val show : exp -> string = val p1 : exp = IntExp 3 val p2 : exp = VarExp "x" val p3 : exp = AppExp (FunExp ("x", VarExp "y"), IntExp 7) File "interp.ml", line 41, characters 10-17: Warning P: this pattern-matching is not exhaustive. Here is an example of a value that is not matched: [] File "interp.ml", line 44, characters 10-20: Warning P: this pattern-matching is not exhaustive. Here is an example of a value that is not matched: [] File "interp.ml", line 33, characters 2-478: Warning P: this pattern-matching is not exhaustive. Here is an example of a value that is not matched: [] val getL : string list -> exp * string list = # let s = getLine ();; ( \ x . x 0 ) val s : string list = ["("; "\\"; "x"; "."; "x"; "0"; ")"] # let e = getL s;; val e : exp * string list = (AppExp (FunExp ("x", VarExp "x"), IntExp 0), []) # let e,_ = getL s;; val e : exp = AppExp (FunExp ("x", VarExp "x"), IntExp 0) # show e;; - : string = "( \\ x . x 0 )" # #use "interp.ml";; val getLine : unit -> string list = type exp = IntExp of int | VarExp of string | FunExp of string * exp | AppExp of exp * exp | PlusExp of exp * exp val show : exp -> string = val p1 : exp = IntExp 3 val p2 : exp = VarExp "x" val p3 : exp = AppExp (FunExp ("x", VarExp "y"), IntExp 7) File "interp.ml", line 41, characters 10-17: Warning P: this pattern-matching is not exhaustive. Here is an example of a value that is not matched: [] File "interp.ml", line 44, characters 10-20: Warning P: this pattern-matching is not exhaustive. Here is an example of a value that is not matched: [] File "interp.ml", line 33, characters 2-478: Warning P: this pattern-matching is not exhaustive. Here is an example of a value that is not matched: [] val getL : string list -> exp * string list = File "interp.ml", line 53, characters 2-251: Warning P: this pattern-matching is not exhaustive. Here is an example of a value that is not matched: AppExp (_, _) val eval : exp -> exp = val rep : unit -> unit = # rep ();; + 0 0 0- : unit = () # #use "interp.ml";; val getLine : unit -> string list = type exp = IntExp of int | VarExp of string | FunExp of string * exp | AppExp of exp * exp | PlusExp of exp * exp val show : exp -> string = val p1 : exp = IntExp 3 val p2 : exp = VarExp "x" val p3 : exp = AppExp (FunExp ("x", VarExp "y"), IntExp 7) File "interp.ml", line 42, characters 10-17: Warning P: this pattern-matching is not exhaustive. Here is an example of a value that is not matched: [] File "interp.ml", line 45, characters 10-20: Warning P: this pattern-matching is not exhaustive. Here is an example of a value that is not matched: [] File "interp.ml", line 33, characters 2-510: Warning P: this pattern-matching is not exhaustive. Here is an example of a value that is not matched: [] val getL : string list -> exp * string list = File "interp.ml", line 54, characters 2-251: Warning P: this pattern-matching is not exhaustive. Here is an example of a value that is not matched: AppExp (_, _) val eval : exp -> exp = val rep : unit -> unit = # rep ();; + 1 1 2- : unit = () # #use "interp.ml";; File "interp.ml", line 86, characters 22-23: Syntax error # #use "interp.ml";; val getLine : unit -> string list = type exp = IntExp of int | VarExp of string | FunExp of string * exp | AppExp of exp * exp | PlusExp of exp * exp val show : exp -> string = val p1 : exp = IntExp 3 val p2 : exp = VarExp "x" val p3 : exp = AppExp (FunExp ("x", VarExp "y"), IntExp 7) File "interp.ml", line 42, characters 10-17: Warning P: this pattern-matching is not exhaustive. Here is an example of a value that is not matched: [] File "interp.ml", line 45, characters 10-20: Warning P: this pattern-matching is not exhaustive. Here is an example of a value that is not matched: [] File "interp.ml", line 33, characters 2-510: Warning P: this pattern-matching is not exhaustive. Here is an example of a value that is not matched: [] val getL : string list -> exp * string list = val subst : exp -> exp -> string -> exp = val eval : exp -> exp = val rep : unit -> unit = # rep ();; ( \ x . + x 1 0 ) 1- : unit = () # ( \ x . + x 1 1 ) Interrupted. # rep ();; ( \ x . + x 1 1 ) 2- : unit = () # rep ();; ( \ z . ( ( z + ) 0 ) \ x . \ y . ( x ( x y ) ) ) \ y . ( 0 ( 0 y ) )- : unit = () # rep ();; ( \ z . ( ( z + ) 0 ) \ x . \ y . ( x ( x y ) ) ) Exception: Match_failure ("interp.ml", 33, 2). # ( \ z . ( ( z \ x . + x 1 ) 0 ) \ x . \ y . ( x ( x y ) ) );; rep ();; Characters 2-3: ( \ z . ( ( z \ x . + x 1 ) 0 ) \ x . \ y . ( x ( x y ) ) ) ^ Illegal character (\\) # rep ();; ( \ z . ( ( z \ x . + x 1 ) 0 ) \ x . \ y . ( x ( x y ) ) ) 2- : unit = () # rep ();; ( \ z . ( ( z \ x . + x 1 ) 0 ) \ x . \ y . ( x ( x ( x y ) ) ) ) 3- : unit = () #