Terminal ocaml $ ocaml Objective Caml version # 1+2;;<ret> # 1+2;; - : int = 3 ;; OCaml <ret> - : int = 3 OC

Similar documents
Jacques Garrigue

Parametric Polymorphism

# let rec sigma (f, n) = # if n = 0 then 0 else f n + sigma (f, n-1);; val sigma : (int -> int) * int -> int = <fun> sigma f n ( : * -> * ) sqsum cbsu

: gettoken(1) module P = Printf exception End_of_system (* *) let _ISTREAM = ref stdin let ch = ref ( ) let read () = (let c =!ch in ch := inp

ML Edinburgh LCF ML Curry-Howard ML ( ) ( ) ( ) ( ) 1

# let st1 = {name = "Taro Yamada"; id = };; val st1 : student = {name="taro Yamada"; id=123456} { 1 = 1 ;...; n = n } # let string_of_student {n

「計算と論理」 Software Foundations その4

「計算と論理」 Software Foundations その3

haskell.gby

プログラミング言語 8 字句解析器(lexer)と構文解析器(parser)

ML 演習 第 4 回

つくって学ぶプログラミング言語 RubyによるScheme処理系の実装

ex01.dvi

VDM-SL VDM VDM-SL Toolbox VDM++ Toolbox 1 VDM-SL VDM++ Web bool

untitled

pptx

compiler-text.dvi

r07.dvi


ohp07.dvi

monad.gby

Emacs ML let start ::= exp (1) exp ::= (2) fn id exp (3) ::= (4) (5) ::= id (6) const (7) (exp) (8) let val id = exp in

untitled

コンピュータ概論

2.2 Sage I 11 factor Sage Sage exit quit 1 sage : exit 2 Exiting Sage ( CPU time 0m0.06s, Wall time 2m8.71 s). 2.2 Sage Python Sage 1. Sage.sage 2. sa

1 # include < stdio.h> 2 # include < string.h> 3 4 int main (){ 5 char str [222]; 6 scanf ("%s", str ); 7 int n= strlen ( str ); 8 for ( int i=n -2; i

ex01.dvi

超初心者用

K227 Java 2

listings-ext

2005 D Pascal CASL ( ) Pascal C 3. A A Pascal TA TA TA

2011 D Pascal CASL II ( ) Pascal C 3. A A Pascal TA TA enshu-

Java updated

1. A0 A B A0 A : A1,...,A5 B : B1,...,B

25 II :30 16:00 (1),. Do not open this problem booklet until the start of the examination is announced. (2) 3.. Answer the following 3 proble

1st-session key

¥¤¥ó¥¿¡¼¥Í¥Ã¥È·×¬¤È¥Ç¡¼¥¿²òÀÏ Âè2²ó

/ SCHEDULE /06/07(Tue) / Basic of Programming /06/09(Thu) / Fundamental structures /06/14(Tue) / Memory Management /06/1

ohp03.dvi

Pascal Pascal Free Pascal CPad for Pascal Microsoft Windows OS Pascal

Java演習(4) -- 変数と型 --

2009 D Pascal CASL II ( ) Pascal C 3. A A Pascal TA TA

PL : pl0 ( ) 1 SableCC ( sablecc ) 1.1 sablecc sablecc Étienne Gagnon [1] Java sablecc sablecc ( ) Visitor DepthFirstAdapter 1 (Depth

( ) kadai4, kadai4.zip.,. 3 cos x [ π, π] Python. ( 100 ), x cos x ( ). (, ). def print cos(): print cos()

Emacs Ruby..

parser.y 3. node.rb 4. CD-ROM

r03.dvi

Dive into Algebraic Effects

r3.dvi

How to read the marks and remarks used in this parts book. Section 1 : Explanation of Code Use In MRK Column OO : Interchangeable between the new part

fp.gby

新・明解Java入門

r02.dvi

How to read the marks and remarks used in this parts book. Section 1 : Explanation of Code Use In MRK Column OO : Interchangeable between the new part

Transcription:

Jacques Garrigue, 2013 8 8-9 OCaml 1 OCaml OCaml ML ML Haskell ML Haskell ML 70 Edinburgh LCF Robin Milner 1 Caml ML OCaml OCaml OCaml-Nagoya OCaml 2007 in OCaml 2007 (Computer Science Library 3) 2007 http://www.math.nagoya-u.ac.jp/~garrigue/lecture/tsukuba13/ http://caml.inria.fr/ OCaml http://ocaml.org/ OCaml http://ocaml.jp/ http://ocaml.jp/refman/ http://wwwfun.kurims.kyoto-u.ac.jp/soft/ocaml/htmlman/ http://www.math.nagoya-u.ac.jp/~garrigue/papers/jssst-ocaml.html PPL http://www.math.nagoya-u.ac.jp/~garrigue/lecture/2006 AW/ 1 Robin Milner (1934 2010) 1991 Turing 1

garrigue@math.nagoya-u.ac.jp 2 2.1 Terminal ocaml $ ocaml Objective Caml version 3.11.1 # 1+2;;<ret> # 1+2;; - : int = 3 ;; OCaml <ret> - : int = 3 OCaml - OCaml int 3 # let x = 1 ;; (* let *) val x : int = 1 val (* *) #quit # #quit;; (* # *) $ 2.2 Emacs 6.emacs Emacs (setq auto-mode-alist (cons ("\\.ml[iylp]?$". caml-mode) auto-mode-alist)) (autoload caml-mode "caml" "Major mode for editing Caml code." t) (autoload run-caml "inf-caml" "Run an inferior Caml process." t) (if window-system (require caml-font)) (setq inferior-caml-program "/usr/local/bin/ocaml") Preview PDF A( ) ( ) \ ( ) 2

OCaml Emacs Emacs ocaml <M-x>run-caml<ret><ret> # Objective Caml version 3.11.1 # # let x = 2+2;;<ret> val x : int = 4 <M-p> <C-c><C-c> <C-c><C-d> ocaml ocaml.ml. <C-x><C-f>test.ml<ret> <tab> ( <tab> ) emacs 21 ocaml ocaml <C-c><C-s> ( ) let x = 3 * 5;; ( <C-a> ) <C-a><C-c><C-e> ocaml ( # ) # val x : int = 15 2.3 Emacs Emacs Caml 3

test.ml let double x = x * 2;; (* double 2 *) let y = 10;; (* y *) y + double y;; (* 3 *) test.ml # #use "test.ml";; val double : int -> int = <fun> val y : int = 10 - : int = 30 #use " ";; #use 3 # let x = "hello" ;; (* let *) val x : string = "hello" # let x = 1 ;; (* *) val x : int = 1 # x = 2 ;; - : bool = false (* = *) # let x = 3 in x+2;; (* *) - : int = 5 # x;; - : int = 1 (* *) # let x = 3 and y = x+2 ;; (* *) val x : int = 3 val y : int = 3 (* x *) # let f (z : int) = (* *) y + z ;; val f : int -> int = <fun> (* -> *) # f 0;; - : int = 3 # let y = 12 ;; val y : int = 12 # f 0;; - : int = 3 (* *) # let f z = y+z ;; (* *) val f : int -> int = <fun> # let f = fun z -> y+z ;; (* *) val f : int -> int = <fun> # (fun z -> y+z) 0;; (* *) - : int = 12 # let p (x : int) (y : int) = (* *) 2 * x - y * y ;; val p : int -> int -> int = <fun> (* -> *) # p 3 4;; (* *) 4

- : int = -10 # let p = fun x y -> 2 * x - y * y ;; (* *) val p : int -> int -> int = <fun> # let p = fun x -> fun y -> 2 * x - y * y ;; (* *) val p : int -> int -> int = <fun> # let q = p 3 ;; (* *) val q : int -> int = <fun> # q 4 ;; (* *) - : int = -10 # let pi = 3.1416 ;; val pi : float = 3.1416 # let twopi = 2 * pi;; This expression has type float but is here used with type int # let twopi = 2 *. pi;; (*! *) This expression has type int but is here used with type float # let twopi = 2. *. pi ;; (*! *) val twopi : float = 6.2832 val ( *. ) : float -> float -> float val pi : float val float : int -> float (* *) val truncate : float -> int (* *) pi # let npi (n : int) = truncate ((float n) *. pi);; val npi : int -> int = <fun> # npi 8;; - : int = 25 # true false;; - : bool = true # A ;; - : char = A # "Hello" ^ " everybody";; - : string = "Hello everybody" # ();; - : unit = () # (1, "one", 1.0);; - : int * string * float = (1, "one", 1.) # [ "little"; "brown"; "fox" ];; - : string array = [ "little"; "brown"; "fox" ] # Array.init 5 (fun i -> i*i);; - : int array = [ 0; 1; 4; 9; 16 ] # [1; 2; 3; 4];; - : int list = [1; 2; 3; 4] 5

int 2 10 30 2 10 30 1 (64 10 62 ) bool true false char 8 string 8 unit () C void float C double t -> u t u t 1 ->... -> t n -> u t 1,..., t n u t 1 *... * t n t 1,..., t n t array t t list t t ref ( ) t ( ) a, b,... * -> (t array ) Char.code : char -> int Char.chr : int -> char string_of_int : int -> string int_of_string : string -> int float : int -> float truncate : float -> int string_of_float : float -> string float_of_string : string -> float Array.of_list : a list -> a array Array.to_list : a array -> a list Char.code Char code String.get : string -> int -> char (* s.[i] *) String.length : string -> int (* *) String.make : int -> char -> string (* n *) Array.get : a array -> int -> a (* a.(i) *) Array.length : a array -> int (* *) Array.init : int -> (int -> a) -> a array (* 0...n-1 *) + - * / mod : int -> int -> int +. -. *. /. ** : float -> float -> float - : int -> int -. : float -> float 6

= <> < > <= >= : a -> a -> bool ==!= : a -> a -> bool a 2 && : bool -> bool -> bool 1 && 2 1 2 1 && 2 1 2 1 2 1 2 ^ : string -> string -> string Array.append : a array -> a array -> a array (* *) @ : a list -> a list -> a list ^ "hello" ^ " world" "hello world" 3.1 1. ocaml 2. val heikin : float -> float -> float 3. val mult : float -> float array -> float array val plus : float array -> float array -> float array +.( ) Array.length Array.init Array.get 4 ML. # let f x y = (x+1, y.[0]);; val f : int -> string -> int * char = <fun> x + int y String.get string # let fst (x,y) = x ;; val fst : a * b -> a = <fun> 7

x y a b x a let # fst ("France", 33) ;; - : string = "France" # fst (5.0, 2.3) ;; - : float = 5. fst string * int -> string float * float -> float Array.of list Array.get Array.init a Array.length 3 ML C ML # let x = ref 1 ;; (* *) val x : int ref = {contents = 1} #!x ;; (* *) - : int = 1 # x := 2 ;; (* *) - : unit = () #!x ;; - : int = 2 # let arr = [ 2; 3; 4 ];; val arr : int array = [ 2; 3; 4 ] # arr.(0) <- 5;; (* *) - : unit = () # arr;; - : int array = [ 5; 3; 4 ] for # let sum (arr : int array) = let r = ref 0 in (* *) for i = 0 to Array.length arr - 1 do r :=!r + arr.(i) done; (* ; *) 8

!r;; (* *) val sum : int array -> int = <fun> # let r = ref [];; val r : _a list ref = {contents = []} # r := [3];; - : unit = () # r;; - : int list ref = contents = [3] # let single () x = [x];; val single : unit -> a -> a list = <fun> # let safe = single ();; val safe : _a -> _a list = <fun> r r int list ref ref Array.init OCaml ref array( ) # single () [];; - : a list list = [[]] (* *) Array.init sum # let iter (f : a -> unit) (arr : a array) = for i = 0 to Array.length arr - 1 do f arr.(i) done;; val iter : ( a -> unit) -> a array -> unit = <fun> # let sum2 arr = let r = ref 0 in iter (fun x -> r :=!r + x) arr;!r ;; val sum2 : int array -> int = <fun> iter for iter sum iter Array.iter # let local x0 (f : a ref -> unit) = let r = ref x0 in f r;!r;; val local : a -> ( a ref -> unit) -> a = <fun> # let sum3 (arr : int array) = local 0 (fun r -> iter (fun x -> r :=!r + x) arr);; val sum3 : int array -> int = <fun> 9

sum map # let map f arr = Array.init (Array.length arr) (fun i -> f arr.(i)) ;; val map : ( a -> b) -> a array -> b array = <fun> # let scalar x v = map (fun x -> x *. x ) v ;; val scalar : float -> float array -> float array = <fun> 2 let f x 1... x n = E f E 1... E n = let x 1 = E 1 and... and x n = E n in E (1) x v ((1) (2) ) x v( ) E E (E x v ) let x = v in E = E{x := v} (2) sum3 arr = local 0 (fun r -> iter (fun x -> r :=!r + x) arr) (1) let x0 = 0 and f r = iter (fun x -> r :=!r + x) arr in let r = ref x0 in f r;!r (2) sum2 arr = let r = ref 0 in (let r = r in iter (fun x -> r :=!r + x) arr);!r (1) let r = ref 0 in let f x = r :=!r + x and arr = arr in for i = 0 to Array.length arr - 1 do f arr.(i) done;!r (2) let r = ref 0 in for i = 0 to Array.length arr - 1 do r :=!r + arr.(i) done;!r = sum arr sum3 sum2 sum map val map : ( a -> b) -> a array -> b array map 1 10

b array a array a array a b val map_array : ( a -> a) -> a array -> a array val map_array : ( a -> b) -> a array -> c array c 4.1 1. val rev_array : a array -> a array 2. f ɛ x f (x) derive f (x) = f(x + ɛ) f(x ɛ) 2ɛ val derive : (float -> float) -> float -> float -> float 3. Array.init val init_matrix : int -> int -> (int -> int -> a) -> a array array # init_matrix 2 3 (fun i j -> 3*i+j);; - : int array array = [ [ 0; 1; 2 ]; [ 3; 4; 5 ] ] 4. f integ Int(f, N, x, x ) = x x N N 1 k=0 f(x k ) + f(x k+1 ) 2 where x k = (N k)x + kx N val integ : (float -> float) -> int -> float -> float -> float 5 http://www.math.nagoya-u.ac.jp/~garrigue/lecture/tsukuba07/ plot.mli (* plot.mli *) val adjust_size : (float * float) list -> unit (* *) val create_curve : (float -> float) -> (float * float) list (* *) val draw_curve : (float * float) list -> unit (* *) 11

1: Plot plot.ml Graphics OCaml plot.mli X11 plot.mli plot.ml $ ocamlc -c plot.mli (* plot.mli -> plot.cmi *) $ ocamlc -c plot.ml (* plot.ml -> plot.cmo *) #load "graphics.cma" ;; (* OCaml *) #load "plot.cmo" ;; (* plot.cmo *) open Plot ;; (* plot.cmi *) adjust_size [-5., 0.; 5., 0.] ;; let curve = create_curve (fun x -> (sin x) ** 2. -. 0.5) ;; adjust_size curve ;; draw_curve curve ;; 1 5.1 1. 2. x val draw_functions : (float -> float) list -> float -> float -> unit List.map : ( a -> b) -> a list -> b list (* Array.map *) 12

List.iter : ( a -> unit) -> a list -> unit (* Array.iter *) List.flatten : a list list -> a list (* *) 3. draw curve draw curve 6 for ( ) # let rec gcd m n = (* let rec *) if n = 0 then m else gcd n (m mod n) ;; val gcd : int -> int -> int = <fun> # gcd 15 70;; - : int = 5 while # let gcd2 m n = let m = ref m and n = ref n in while!n <> 0 do (* while *) let n =!m mod!n in (* n! *) m :=!n; n := n (* *) done;!m ;; val gcd2 : int -> int -> int = <fun> gcd (m, n 0 ) n = 0 0 m m m n m n > 0 k < n m gcd m k m k 0 m mod n < n gcd m n = gcd n (m mod n) = (n m mod n ) m = q n + m mod n p n m mod n p m p m n m mod n = m q n gcd m n = (n m mod n ) = (m n ). # let rec fib n = if n < 2 then 1 else fib (n-1) + fib (n-2) ;; val fib : int -> int = <fun> # fib 5;; - : int = 8 13

# #trace fib;; (* *) fib is now traced. # fib 4;; fib <-- 4 fib <-- 2 fib <-- 0 fib --> 1 fib <-- 1 (* fib 1 *) fib --> 1 fib --> 2 fib <-- 3 fib <-- 1 (* *) fib --> 1 fib <-- 2 fib <-- 0 fib --> 1 fib <-- 1 (* *) fib --> 1 fib --> 2 fib --> 3 fib --> 5 - : int = 5 6.1 fib # [1; 2; 3];; (* *) - : int list = [1; 2; 3] # 1 :: [2; 3];; (* cons( ) *) - : int list = [1; 2; 3] # 1 :: (2 :: (3 :: []));; (* *) - : int list = [1; 2; 3] # List.hd [1;2;3];; (* *) - : int = 1 # List.tl [1;2;3];; (* *) - : int list = [2; 3] List.length : a list -> int List.hd : a list -> a List.tl : a list -> a list List.nth : a list -> int -> a List.rev : a list -> a list List.append : a list -> a list -> a list (* l1 @ l2 *) List.flatten : a list list -> a list List.iter : ( a -> unit) -> a list -> unit List.map : ( a -> b) -> a list -> b list List.fold_left : ( a -> b -> a) -> a -> b list -> a List.fold_right : ( a -> b -> b) -> a list -> b -> b List.for_all : ( a -> bool) -> a list -> bool List.exists : ( a -> bool) -> a list -> bool 14

List.mem : a -> a list -> bool List.filter : ( a -> bool) -> a list -> a list List.split : ( a * b) list -> a list * b list List.combine : a list -> b list -> ( a * b) list List.assoc : a -> ( a * b) list -> b List.mem_assoc : a -> ( a * b) list -> bool List.remove_assoc : a -> ( a * b) list -> ( a * b) list... 6.2 let hd l = match l with [] -> failwith "List.hd" (* *) a :: _ -> a ;; (* *) let tl l = match l with [] -> failwith "List.tl" _ :: t -> t ;; (* *) match with 1 -> 1... n -> n i i ( ) i let rec length l = match l with [] -> 0 _ :: l -> 1 + length l ;; let rec rev_append l1 l2 = match l1 with [] -> l2 a :: l -> rev_append l (a :: l2) ;; let rev l = rev_append l [] ;; 6.3 1. append 2. rev 3. ( ) 15

val eval_poly : int list -> int -> int # eval_poly [1; 0; 3] 2 ;; - : int = 13 (* 1 + 0*2 + 3*4 *) SEND + MORE = MONEY (S M 1 9, E, N, D, M, O, R, Y 0 9 SEND MORE 10 MONEY ) (* *) val check : (char * int) list -> bool = <fun> (*. *) val remove : a -> a list -> a list (* *) # let rec search dict letters numbers = match letters with [] -> if check dict then [dict] else [] a :: letters -> (* letters <- List.tl letters *) let choose n = search ((a,n)::dict) letters (remove n numbers) in List.flatten (List.map choose numbers) ;; val search : (char * int) list -> char list -> int list -> (char * int) list list = <fun> # let rec interval m n = if m > n then [] else m :: interval (m+1) n ;; val interval : int -> int -> int list = <fun> # let solve () = search [] [ S ; E ; N ; D ; M ; O ; R ; Y ] (interval 0 9) ;; val solve : unit -> (char * int) list list = <fun> # solve () ;; - : (char * int) list list = [[( Y,2);...]] 6.4 1. remove : remove 3 [4; 3; 3; 5] [4;3;5]. 2. check List.map, List.assoc eval poly check search 7 type = 1 [of 1 ]... n [of n ] 16

# type a mylist = Nil (* [] *) Cons of a * a mylist ;; (* :: *) type a mylist = Nil Cons of a * a mylist # let rec mylist_of_list l = match l with [] -> Nil a :: t -> Cons (a, mylist_of_list t) ;; val mylist_of_list : a list -> a mylist = <fun> # mylist_of_list [1;2;3];; - : int mylist = Cons (1, Cons (2, Cons (3, Nil))) # let my_hd l = match l with (* *) Nil -> failwith "my_hd" Cons(a,_) -> a ;; val my_hd : a mylist -> a = <fun> type a mylist = Nil Cons of a * a mylist One of a (* mylist *) # let my_hd l = (* *) match l with Nil -> failwith "my_hd" Cons(a,_) -> a ;; Warning P: this pattern-matching is not exhaustive. Here is an example of a value that is not matched: One _ val my_hd : a mylist -> a = <fun> ( ) ::= + ( ) 5 2 + 3 (3 + y) 12 type expr = Num of int Var of string Plus of expr * expr Mult of expr * expr # let map_expr f e = (* map *) match e with Num _ Var _ -> e 17

Plus (e1, e2) -> Plus (f e1, f e2) Mult (e1, e2) -> Mult (f e1, f e2) val map_expr : (expr -> expr) -> expr -> expr # let rec subst env e = (* *) match e with Var x when List.mem_assoc x env -> Num (List.assoc x env) e -> map_expr (subst env) e val subst : (string * int) list -> expr -> expr map expr subst # let rec eval e = match map_expr eval e with Plus (Num x, Num y) -> Num (x + y) Mult (Num x, Num y) -> Num (x * y) e -> e val eval : expr -> expr = <fun> # let e = subst ["x", 3; "z", 2] (Plus (Var "y", Mult (Var "x", Var "z")));; val e : expr = Plus (Var "y", Mult (Num 3, Num 2)) # let e = eval e;; val e : expr = Plus (Var "y", Num 6) 7.1 1. expr 2. 3. expr 8 OCaml Camlp4 # #load"camlp4o.cma";; Camlp4 Parsing version 3.11.1 # open Genlex;; # let lexer = Genlex.make_lexer ["+";"*";"(";")"] ;; val lexer : char Stream.t -> Genlex.token Stream.t = <fun> # let s = lexer (Stream.of_string "1 2 3 4");; val s : Genlex.token Stream.t = <abstr> # (parser [< x >] -> x) s ;; (* *) - : Genlex.token = Int 1 # (parser [< Int 1 >] -> "ok") s ;; (* Int 1 *) Exception: Stream.Failure. (* *) # (parser [< Int 1 >] -> "one" [< Int 2 >] -> "two") s ;; - : string = "two" (* Int 2 *) 18

(* *) # let rec accumulate parse accu = parser [< e = parse accu; s >] -> accumulate parse e s [< >] -> accu;; val accumulate : ( a -> b Stream.t -> a) -> a -> b Stream.t -> a = <fun> e = parse accu s parse accu s e parse Stream.Failure Stream.Failure (* *) # let left_assoc parse op wrap = let parse accu = parser [< Kwd k when k = op; s >] -> wrap accu (parse s) in parser [< e1 = parse; e2 = accumulate parse e1 >] -> e2;; val left_assoc : (Genlex.token Stream.t -> a) -> string -> ( a -> a -> a) -> Genlex.token Stream.t -> a = <fun> when true 8.1 left assoc # let rec parse_simple = parser [< Int n >] -> Num n [< Ident x >] -> Var x [< Kwd"("; e = parse_expr; Kwd")" >] -> e and parse_mult s = left_assoc parse_simple "*" (fun e1 e2 -> Mult(e1,e2)) s and parse_expr s = left_assoc parse_mult "+" (fun e1 e2 -> Plus(e1,e2)) s ;; val parse_simple : Genlex.token Stream.t -> expr = <fun> val parse_mult : Genlex.token Stream.t -> expr = <fun> val parse_expr : Genlex.token Stream.t -> expr = <fun> # let parse_string s = match lexer (Stream.of_string s) with parser [< e = parse_expr; _ = Stream.empty >] -> e;; val parse_string : string -> expr = <fun> # let e = parse_string "5+x*(4+x)";; val e : expr = Plus (Num 5, Mult (Var "x", Plus (Num 4, Var "x"))) # eval (subst ["x", 3] e);; - : expr = Num 26 Format # let rec print_expr prio ppf e = let printf fmt = Format.fprintf ppf fmt in match e with Num x -> printf "%d" x Var x -> printf "%s" x Mult (e1, e2) -> 19

printf "@[%a *@ %a@]" (print_expr 1) e1 (print_expr 1) e2 Plus (e1, e2) as e -> if prio > 0 then printf "(%a)" (print_expr 0) e else printf "@[%a +@ %a@]" (print_expr 0) e1 (print_expr 0) e2;; val print_expr : int -> Format.formatter -> expr -> unit # let print_expr0 = print_expr 0;; val print_expr0 : Format.formatter -> expr -> unit = <fun> # #install printer print_expr0;; # Plus(Num 3, Var "a");; - : expr = 3 + a read-eval-print # let toplevel () = while true do try (* ( ) *) print_string "? "; (*? *) let s = read_line() in (* *) let e = parse_string s in (* expr *) let e = eval e in (* *) Format.printf "=> %a@." (print_expr 0) e (* *) with (* *) Stream.Failure -> () Stream.Error _ -> Format.printf "Syntax error!@." done val toplevel : unit -> unit = <fun> # toplevel ();;? 5+3*2 => 11? 5+3*a => 5 + 3 * a? a+3*2 => a + 6? <C-c><C-c>Interrupted. 8.2 1. 2. let = in lexer let lexer = Genlex.make_lexer ["+";"*";"(";")";"=";"let";"in"] ;; subst eval # toplevel ();;? let x = 1 + 1 in x + (let y = 1+2 in y*y) => 11 20