Jacques Garrigue

Size: px
Start display at page:

Download "Jacques Garrigue"

Transcription

1 Jacques Garrigue

2 Garrigue 1

3 Garrigue 2 $ print_lines () > for i in $1; do > echo $i > done $ print_lines "a b c" a b c

4 Garrigue 3 Emacs Lisp (defun print-lines (lines) (dolist (str lines) (insert str) (insert "\n"))) (print-lines ("a" "b c")) a b c (print-lines (("a") ("b" "c"))) error print-lines

5 Garrigue 4 C #include<stdio.h> void print_lines(char *lines[]) { while (*lines!= NULL) printf("%s\n", *lines++); } int main() { char *lines[] = { "a", "b c", NULL }; print_lines(lines); } $./print_lines a b c

6 Garrigue 5 C #include<stdio.h> void print_lines(char *lines[]) { while (*lines!= NULL) printf("%s\n", *lines++); } int main() { char *lines[] = { "a", "b c", (char*)3, NULL }; print_lines(lines); } $./print_lines a b c Segmentation fault

7 Garrigue 6 C ( lines++) ( (char*)3) struct person { char name[20]; int age; } union person_or_id { struct person *person; int id; }

8 Garrigue 7 1 P P

9 Garrigue Church Turing (Curry-Howard )

10 Garrigue 9 τ ::= b τ τ t ::= x λ(x : τ) t t(t) λ(plus : nat nat nat) λ(y : nat) plus(y)(y)

11 Garrigue 10 Γ ::= {x 1 : τ 1,..., x n : τ n } Γ t τ Γ t : τ x : τ Γ Γ x : τ Γ, x : τ t 1 : τ 1 Γ λ(x : τ) t 1 : τ τ 1 Γ t 1 : τ 2 τ Γ t 2 : τ 2 Γ t 1 (t 2 ) : τ

12 Garrigue 11 v ::= c (η, λ(x : τ) t) η ::= {x 1 v 1,..., x n v n } η = t v η t v x v η η = x v η = λ(x : τ) t (η, λ(x : τ) t) η = t 1 (η, λ(x : τ) t ) η = t 2 v 2 η, x v 2 = t v 3 η = t 1 (t 2 ) v 3

13 Garrigue 12 2 t t : τ t v : = t v

14 Garrigue 13 type a = C 1 of τ τ 1m1 C 2 of τ τ 2m2. C n of τ n1... τ nmn C i a (m i = 0 Γ C i : a ) Γ t 1 : τ i1... Γ t mi : τ imi Γ C i (t 1,..., t mi ) : a

15 Garrigue 14 a b type pair_a_b = Pair_a_b of a * b a type option_a = Some_a of a None a type list_a = Nil Cons of a * list_a [a1; a2; a3] = Cons (a1, Cons (a2, Cons (a3, Nil))) type nat = Zero Succ of nat 3 = Succ (Succ (Succ (Zero)))

16 Garrigue 15 match match t with C 1 (x 1,..., x m1 ) t 1. C n (x n,..., x mn ) t n Γ t : a Γ, x 1 : τ i1,..., x mi : τ imi t i : τ (1 i n) Γ match t with C 1 (x 1,..., x m1 ) t 1... C n (x n,..., x mn ) t n : τ η = t C i (v 1,..., v mi ) η, x 1 v 1,..., x mi v mi = t i v η = match t with C 1 (x 1,..., x m1 ) t 1... C n (x n,..., x mn ) t n v

17 Garrigue 16 OCaml let fst_a_b (p : pair_a_b) = match p with Pair_a_b (a,b) -> a val fst_a_b : pair_a_b -> a let snd_a_b (p : pair_a_b) = match p with Pair_a_b (a,b) -> b val snd_a_b : pair_a_b -> b let rec add (m : nat) (n : nat) = match m with Zero -> n Succ m -> Succ (add (m ) (n)) val add : nat -> nat -> nat

18 Garrigue 17 type ( a, b) pair = Pair of a * b type a option = Some of a None type a list = Nil Cons of a * a list let fst (p : ( a, b) pair) = match p with Pair (a,b) -> a val fst : ( a, b) pair -> a let snd (p : ( a, b) pair) = match p with Pair (a,b) -> b val snd : ( a, b) pair -> b let rec append (l1 : a list) (l2 : a list) = match l1 with None -> l2 Cons (a, l1 ) -> Cons (a, append (l1 ) (l2)) val append : a list -> a list -> a list

19 Garrigue 18 let rec type a recc = In of ( a recc -> a) let out (In x) = x val out : a recc -> a recc -> a let y (f : ( a -> b) -> ( a -> b)) = (fun x a -> f (out x x) a) (In (fun x a -> f (out x x) a)) val y : (( a -> b) -> a -> b) -> a -> b y

20 Garrigue 19 C OCaml Haskell Damas Milner 3 ( ) P Γ Γ P : τ τ τ τ

21 Garrigue 20 Γ f : α f Γ x : α x Γ g : α g Γ x : α x Γ f(x) : α 2 Γ g(x) : α 3 Γ f(x)(g(x)) : α 1 λf λg λx f(x)(g(x)) : α Γ = f : α f, g : α g, x : α x {α = α f α g α x α 1, α 2 = α 3 α 1, α f = α x α 2, α g = α x α 3 } mgu( ) σ σ(α) = (α x α 3 α 1 ) (α x α 3 ) α x α 1

22 Garrigue 21

23 Garrigue 22 let fst p = match p with Pair (a,b) -> a val fst : ( a, b) pair -> a let snd p = match p with Pair (a,b) -> b val snd : ( a, b) pair -> b let rec append l1 l2 = match l1 with None -> l2 Cons (a, l1 ) -> Cons (a, append l1 l2) val append : a list -> a list -> a list

24 Garrigue 23

25 Garrigue 24 let l = [ Feet 3.0; Mm 33.2 ] val l : [> Feet of float Mm of float ] list let normalize len = match len with Feet n -> Inch (n *. 12.) Inch n -> Inch n Cm n -> Mm (n *. 10.) Mm n -> Mm n val normalize : [< Cm of float Feet of float Inch of float Mm of float ] -> [> Inch of float Mm of float ]

26 Garrigue 25 ( ) ( a list as a) let rec length l = match l with Nil -> 0 Cons (a, t) -> 1 + length t val length : ([< Cons of b * a Nil ] as a) -> int ([ Cons of b * [ Cons of b * a] Nil ] as a)

27 Garrigue 26 (U, L, T ) (Fin(L) L) Fin(L) Fin(L T ) U L [> Feet of float Mm of float ] list = α :: (L, {Feet, Mm}, {Feet float, Mm float}) α list [< C of f F of f I of f M of f ] -> [> I of f M of f ] = α 1 :: ({C, F, I, M},, {C f, F f, I f, M f}), α 2 :: (L, {I, M}, {I f, M f}) α 1 α 2

28 Garrigue 27 mgu mgu {α = [< A of int B], α = [< A of α 1 B]} σ(α 1 ) = int {α = [ B], α 1 = bool} σ = {α [ B]} σ = {α [< A of int & α 1 B]} A α α 1 = int

29 Garrigue 28 LablGL OpenGL 3D C Lisp LablTk Tcl/Tk GUI LablGTK Gtk+ GUI C Enum

30 Garrigue 29 (GADTs) type _ expr = Int : int -> int expr Add : (int -> int -> int) expr App : ( a -> b) expr * a expr -> b expr App (Add, Int 3) : (int -> int) expr

31 Garrigue 30 GADT let rec eval : type a. a expr -> a = function Int n -> n (* a = int *) Add -> (+) (* a = int -> int -> int *) App (f, x) -> eval f (eval x) (* *) val eval : a expr -> a = <fun> eval (App (App (Add, Int 3), Int 4));; - : int = 7

32 Garrigue 31 GADT type _ t = Int : int t let f (type a) (x : a t) = match x with Int -> 1 (* a = int *)

33 Garrigue 32 let f (type a) (x : a t) = match x with Int -> 1 (* a = int *) Haskell(GHC) OK OCaml

34 Garrigue 33 GADT exception Axiom type falso and p not = p -> falso let ex_falso (f : falso) = raise Axiom type ( a, b) ior = Inl of a Inr of b let classic () : ( a, a not) ior = raise Axiom (* Drinkers Paradox: x, Drinks(x ) y, Drinks(y) *) type _ drinks type all_drink = {all: y. unit -> y drinks} type non_drinker = Nd : x drinks not -> non_drinker type drinkers_paradox = Drinker : ( x drinks -> all_drink) -> drinkers_paradox let proof () : drinkers_paradox = match classic () with Inl (Nd nd) -> Drinker (fun d -> ex_falso (nd d)) Inr nnd -> Drinker (fun d -> {all = fun () -> match classic () with Inr nd -> ex_falso (nnd (Nd nd)) Inl d -> d})

35 Garrigue 34 let third l = match l with Cons (a, Cons (b, (Cons (c, l)))) -> c Cons (a, Cons (b, Nil)) -> b Nil -> raise Not_found Warning 8: this pattern-matching is not exhaustive. Here is an example of a value that is not matched: Cons (_, Nil)

36 Garrigue 35 let f = function A -> 1 B -> 2 val f : [< A B ] -> int let g = function A -> 1 B -> 2 _ -> 3 val g : [> A B ] -> int let h = function A, A -> 1 A, B -> 2 B, _ -> 3 val h : [< A B ] * [< A B ] -> int

37 Garrigue 36 GADT GADT type _ t = Int : int t Bool : bool t let g : int t -> int = function Int -> 1 (* bool *) let h : type a. a t -> a t -> bool = fun x y -> match x, y with Int, Int -> true Bool, Bool -> true (* *)

38 Garrigue 37 GADT t let f : (char t) option -> int = function None -> 0 f char t int t bool t f t C i : ᾱ, ( β, τ i1... τ imi ) τ t GADT

39 Garrigue 38 OCaml

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

ML Edinburgh LCF ML Curry-Howard ML ( ) ( ) ( ) ( ) 1 More Logic More Types ML/OCaml GADT Jacques Garrigue ( ) Jacques Le Normand (Google) Didier Rémy (INRIA) @garriguejej ocamlgadt ML Edinburgh LCF ML Curry-Howard ML ( ) ( ) ( ) ( ) 1 ( ) ML type nebou and

More information

Parametric Polymorphism

Parametric Polymorphism ML 2 2011/04/19 Parametric Polymorphism Type Polymorphism ? : val hd_int : int list - > int val hd_bool : bool list - > bool val hd_i_x_b : (int * bool) list - > int * bool etc. let hd_int = function (x

More information

jssst-ocaml.mgp

jssst-ocaml.mgp Objective Caml Jacques Garrigue Kyoto University garrigue@kurims.kyoto-u.ac.jp Objective Caml? 2 Objective Caml GC() Standard MLHaskell 3 OCaml () OCaml 5 let let x = 1 + 2 ;; val x : int = 3 ;; val-:

More information

Objective Caml 3.12 Jacques Garrigue ( ) with Alain Frisch (Lexifi), OCaml developper team (INRIA)

Objective Caml 3.12 Jacques Garrigue ( )   with Alain Frisch (Lexifi), OCaml developper team (INRIA) Objective Caml 3.12 Jacques Garrigue ( ) http://www.math.nagoya-u.ac.jp/~garrigue/ with Alain Frisch (Lexifi), OCaml developper team (INRIA) Jacques Garrigue Modules in Objective Caml 3.12 1 Objective

More information

# 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

# 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 II 4 : 2001 11 7 keywords: 1 OCaml OCaml (first-class value) (higher-order function) 1.1 1 2 + 2 2 + + n 2 sqsum 1 3 + 2 3 + + n 3 cbsum # let rec sqsum n = # if n = 0 then 0 else n * n + sqsum (n - 1)

More information

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

# let st1 = {name = Taro Yamada; id = };; val st1 : student = {name=taro Yamada; id=123456} { 1 = 1 ;...; n = n } # let string_of_student {n II 6 / : 2001 11 21 (OCaml ) 1 (field) name id type # type student = {name : string; id : int};; type student = { name : string; id : int; } student {} type = { 1 : 1 ;...; n : n } { 1 = 1 ;...; n = n

More information

ML λ λ 1 λ 1.1 λ λ λ e (λ ) ::= x ( ) λx.e (λ ) e 1 e 2 ( ) ML λx.e Objective Caml fun x -> e x e let 1

ML λ λ 1 λ 1.1 λ λ λ e (λ ) ::= x ( ) λx.e (λ ) e 1 e 2 ( ) ML λx.e Objective Caml fun x -> e x e let 1 2005 sumii@ecei.tohoku.ac.jp 2005 6 24 ML λ λ 1 λ 1.1 λ λ λ e (λ ) ::= x ( ) λx.e (λ ) e 1 e 2 ( ) ML λx.e Objective Caml fun x -> e x e let 1 let λ 1 let x = e1 in e2 (λx.e 2 )e 1 e 1 x e 2 λ 3 λx.(λy.e)

More information

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

「計算と論理」  Software Foundations   その3 Software Foundations 3 cal17@fos.kuis.kyoto-u.ac.jp October 24, 2017 ( ) ( 3) October 24, 2017 1 / 47 Lists.v ( ) ( ) ( ) ( 3) October 24, 2017 2 / 47 ( ) Inductive natprod : Type := pair : nat nat natprod.

More information

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

「計算と論理」  Software Foundations   その4 Software Foundations 4 cal17@fos.kuis.kyoto-u.ac.jp http://www.fos.kuis.kyoto-u.ac.jp/~igarashi/class/cal/ November 7, 2017 ( ) ( 4) November 7, 2017 1 / 51 Poly.v ( ) ( 4) November 7, 2017 2 / 51 : (

More information

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

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 Emacs, {l06050,sasano}@sic.shibaura-it.ac.jp Eclipse Visual Studio Standard ML Haskell Emacs 1 Eclipse Visual Studio variable not found LR(1) let Emacs Emacs Emacs Java Emacs JDEE [3] JDEE Emacs Java 2

More information

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

: gettoken(1) module P = Printf exception End_of_system (* *) let _ISTREAM = ref stdin let ch = ref ( ) let read () = (let c =!ch in ch := inp 7 OCaml () 1. 2. () (compiler) (interpreter) 2 OCaml (syntax) (BNF,backus normal form ) 1 + 2; let x be 2-1 in x; ::= ; let be in ; ::= + - ::= * / ::= 7.1 ( (printable characters) (tokens) 1 (lexical

More information

koba/class/soft-kiso/ 1 λ if λx.λy.y false 0 λ typed λ-calculus λ λ 1.1 λ λ, syntax τ (types) ::= b τ 1 τ 2 τ 1

koba/class/soft-kiso/ 1 λ if λx.λy.y false 0 λ typed λ-calculus λ λ 1.1 λ λ, syntax τ (types) ::= b τ 1 τ 2 τ 1 http://www.kb.ecei.tohoku.ac.jp/ koba/class/soft-kiso/ 1 λ if λx.λy.y false 0 λ typed λ-calculus λ λ 1.1 λ 1.1.1 λ, syntax τ (types) ::= b τ 1 τ 2 τ 1 τ 2 M (terms) ::= c τ x M 1 M 2 λx : τ.m (M 1,M 2

More information

Copyright c 2008 Zhenjiang Hu, All Right Reserved.

Copyright c 2008 Zhenjiang Hu, All Right Reserved. 2008 10 27 Copyright c 2008 Zhenjiang Hu, All Right Reserved. (Bool) True False data Bool = False True Remark: not :: Bool Bool not False = True not True = False (Pattern matching) (Rewriting rules) not

More information

2

2 2011.11.11 1 2 MapReduce 3 4 5 6 Functional Functional Programming 7 8 9 10 11 12 13 [10, 20, 30, 40, 50] 0 n n 10 * 0 + 20 * 1 + 30 * 2 + 40 * 3 + 50 *4 = 400 14 10 * 0 + 20 * 1 + 30 * 2 + 40 * 3 + 50

More information

Copyright c 2006 Zhenjiang Hu, All Right Reserved.

Copyright c 2006 Zhenjiang Hu, All Right Reserved. 1 2006 Copyright c 2006 Zhenjiang Hu, All Right Reserved. 2 ( ) 3 (T 1, T 2 ) T 1 T 2 (17.3, 3) :: (Float, Int) (3, 6) :: (Int, Int) (True, (+)) :: (Bool, Int Int Int) 4 (, ) (, ) :: a b (a, b) (,) x y

More information

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

1. A0 A B A0 A : A1,...,A5 B : B1,...,B 1. A0 A B A0 A : A1,...,A5 B : B1,...,B12 2. 3. 4. 5. A0 A, B Z Z m, n Z m n m, n A m, n B m=n (1) A, B (2) A B = A B = Z/ π : Z Z/ (3) A B Z/ (4) Z/ A, B (5) f : Z Z f(n) = n f = g π g : Z/ Z A, B (6)

More information

Int Int 29 print Int fmt tostring 2 2 [19] ML ML [19] ML Emacs Standard ML M M ::= x c λx.m M M let x = M in M end (M) x c λx.

Int Int 29 print Int fmt tostring 2 2 [19] ML ML [19] ML Emacs Standard ML M M ::= x c λx.m M M let x = M in M end (M) x c λx. 1, 2 1 m110057@shibaura-it.ac.jp 2 sasano@sic.shibaura-it.ac.jp Eclipse Visual Studio ML Standard ML Emacs 1 ( IDE ) IDE C C++ Java IDE IDE IDE IDE Eclipse Java IDE Java Standard ML 1 print (Int. 1 Int

More information

r08.dvi

r08.dvi 19 8 ( ) 019.4.0 1 1.1 (linked list) ( ) next ( 1) (head) (tail) ( ) top head tail head data next 1: NULL nil ( ) NULL ( NULL ) ( 1 ) (double linked list ) ( ) 1 next 1 prev 1 head cur tail head cur prev

More information

haskell.gby

haskell.gby Haskell 1 2 3 Haskell ( ) 4 Haskell Lisper 5 Haskell = Haskell 6 Haskell Haskell... 7 qsort [8,2,5,1] [1,2,5,8] "Hello, " ++ "world!" "Hello, world!" 1 + 2 div 8 2 (+) 1 2 8 div 2 3 4 map even [1,2,3,4]

More information

Functional Programming

Functional Programming PROGRAMMING IN HASKELL プログラミング Haskell Chapter 10 - Declaring Types and Classes 型とクラスの定義 愛知県立大学情報科学部計算機言語論 ( 山本晋一郎 大久保弘崇 2011 年 ) 講義資料オリジナルは http://www.cs.nott.ac.uk/~gmh/book.html を参照のこと 0 型宣言 (Type Declarations)

More information

ohp08.dvi

ohp08.dvi 19 8 ( ) 2019.4.20 1 (linked list) ( ) next ( 1) (head) (tail) ( ) top head tail head data next 1: 2 (2) NULL nil ( ) NULL ( NULL ) ( 1 ) (double linked list ) ( 2) 3 (3) head cur tail head cur prev data

More information

untitled

untitled II 4 Yacc Lex 2005 : 0 1 Yacc 20 Lex 1 20 traverse 1 %% 2 [0-9]+ { yylval.val = atoi((char*)yytext); return NUM; 3 "+" { return + ; 4 "*" { return * ; 5 "-" { return - ; 6 "/" { return / ; 7 [ \t] { /*

More information

平成 19 年度 ( 第 29 回 ) 数学入門公開講座テキスト ( 京都大学数理解析研究所, 平成 19 ~8 年月 72 月日開催 30 日 ) 1 PCF (Programming language for Computable Functions) PCF adequacy adequacy

平成 19 年度 ( 第 29 回 ) 数学入門公開講座テキスト ( 京都大学数理解析研究所, 平成 19 ~8 年月 72 月日開催 30 日 ) 1 PCF (Programming language for Computable Functions) PCF adequacy adequacy 1 PCF (Programming language for Computable Functions) PCF adequacy adequacy 2 N X Y X Y f (x) f x f x y z (( f x) y) z = (( f (x))(y))(z) X Y x e X Y λx. e x x 2 + x + 1 λx. x 2 + x + 1 3 PCF 3.1 PCF PCF

More information

ohp03.dvi

ohp03.dvi 19 3 ( ) 2019.4.20 CS 1 (comand line arguments) Unix./a.out aa bbb ccc ( ) C main void int main(int argc, char *argv[]) {... 2 (2) argc argv argc ( ) argv (C char ) ( 1) argc 4 argv NULL. / a. o u t \0

More information

6-1

6-1 6-1 (data type) 6-2 6-3 ML, Haskell, Scala Lisp, Prolog (setq x 123) (+ x 456) (setq x "abc") (+ x 456) ; 6-4 ( ) subtype INDEX is INTEGER range -10..10; type DAY is (MON, TUE, WED, THU, FRI, SAT, SUN);

More information

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

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

More information

org/ghc/ Windows Linux RPM 3.2 GHCi GHC gcc javac ghc GHCi(ghci) GHCi Prelude> GHCi :load file :l file :also file :a file :reload :r :type expr :t exp

org/ghc/ Windows Linux RPM 3.2 GHCi GHC gcc javac ghc GHCi(ghci) GHCi Prelude> GHCi :load file :l file :also file :a file :reload :r :type expr :t exp 3 Haskell Haskell Haskell 1. 2. 3. 4. 5. 1. 2. 3. 4. 5. 6. C Java 3.1 Haskell Haskell GHC (Glasgow Haskell Compiler 1 ) GHC Haskell GHC http://www.haskell. 1 Guarded Horn Clauses III - 1 org/ghc/ Windows

More information

r03.dvi

r03.dvi 19 ( ) 019.4.0 CS 1 (comand line arguments) Unix./a.out aa bbb ccc ( ) C main void... argc argv argc ( ) argv (C char ) ( 1) argc 4 argv NULL. / a. o u t \0 a a \0 b b b \0 c c c \0 1: // argdemo1.c ---

More information

1st-session key

1st-session key 1 2013/11/29 Project based Learning: Soccer Agent Program 1 2012/12/9 Project based Learning: Soccer Agent Program PBL Learning by doing Schedule 1,2 2013 11/29 Make 2013 12/6 2013 12/13 2013 12/20 2014

More information

2 ID POS 1... 1 2... 2 2.1 ID POS... 2 2.2... 3 3... 5 3.1... 5 3.2... 6 3.2.1... 6 3.2.2... 7 3.3... 7 3.3.1... 7 3.3.2... 8 3.3.3... 8 3.4... 9 4... 11 4.1... 11 4.2... 15 4.3... 27 5... 35... 36...

More information

r3.dvi

r3.dvi 2012 3 / Lisp(2) 2012.4.19 1 Lisp 1.1 Lisp Lisp (1) (setq) (2) (3) setq defun (defun (... &aux...)...) ( ) ( nil ) [1]> (defun sisoku (x y &aux wa sa sho seki) (setq wa (+ x y)) (setq sa (- x y)) (setq

More information

I: 2 : 3 +

I: 2 : 3 + I: 1 I: 2008 I: 2 : 3 + I: 3, 3700. (ISBN4-00-010352-0) H.P.Barendregt, The lambda calculus: its syntax and semantics, Studies in logic and the foundations of mathematics, v.103, North-Holland, 1984. (ISBN

More information

1. 1 A : l l : (1) l m (m 3) (2) m (3) n (n 3) (4) A α, β γ α β + γ = 2 m l lm n nα nα = lm. α = lm n. m lm 2β 2β = lm β = lm 2. γ l 2. 3

1. 1 A : l l : (1) l m (m 3) (2) m (3) n (n 3) (4) A α, β γ α β + γ = 2 m l lm n nα nα = lm. α = lm n. m lm 2β 2β = lm β = lm 2. γ l 2. 3 1. 1 A : l l : (1) l m (m 3) (2) m (3) n (n 3) (4) A 2 1 2 1 2 3 α, β γ α β + γ = 2 m l lm n nα nα = lm. α = lm n. m lm 2β 2β = lm β = lm 2. γ l 2. 3 4 P, Q R n = {(x 1, x 2,, x n ) ; x 1, x 2,, x n R}

More information

a n a n ( ) (1) a m a n = a m+n (2) (a m ) n = a mn (3) (ab) n = a n b n (4) a m a n = a m n ( m > n ) m n 4 ( ) 552

a n a n ( ) (1) a m a n = a m+n (2) (a m ) n = a mn (3) (ab) n = a n b n (4) a m a n = a m n ( m > n ) m n 4 ( ) 552 3 3.0 a n a n ( ) () a m a n = a m+n () (a m ) n = a mn (3) (ab) n = a n b n (4) a m a n = a m n ( m > n ) m n 4 ( ) 55 3. (n ) a n n a n a n 3 4 = 8 8 3 ( 3) 4 = 8 3 8 ( ) ( ) 3 = 8 8 ( ) 3 n n 4 n n

More information

fp.gby

fp.gby 1 1 2 2 3 2 4 5 6 7 8 9 10 11 Haskell 12 13 Haskell 14 15 ( ) 16 ) 30 17 static 18 (IORef) 19 20 OK NG 21 Haskell (+) :: Num a => a -> a -> a sort :: Ord a => [a] -> [a] delete :: Eq a => a -> [a] -> [a]

More information

(CC Attribution) Lisp 2.1 (Gauche )

(CC Attribution) Lisp 2.1 (Gauche ) http://www.flickr.com/photos/dust/3603580129/ (CC Attribution) Lisp 2.1 (Gauche ) 2 2000EY-Office 3 4 Lisp 5 New York The lisps Sammy Tunis flickr lisp http://www.flickr.com/photos/dust/3603580129/ (CC

More information

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

つくって学ぶプログラミング言語 RubyによるScheme処理系の実装 Ruby Scheme 2013-04-16 ( )! SICP *1 ;-) SchemeR SICP MIT * 1 Structure and Interpretaion of Computer Programs 2nd ed.: 2 i SchemeR Ruby Ruby Ruby Ruby & 3.0 Ruby ii https://github.com/ichusrlocalbin/scheme_in_ruby

More information

構造化プログラミングと データ抽象

構造化プログラミングと データ抽象 計算の理論 後半第 3 回 λ 計算と型システム 本日の内容 λ 計算の表現力 ( 前回のつづき ) 前回の復習 不動点演算子と再帰 λ 計算の重要な性質 チャーチ ロッサー性 簡約戦略 型付き λ 計算 ブール値 組 ブール値と組の表現 ( 復習 ) true, false を受け取り 対応する要素を返す関数 として表現 T = λt.λf.t F = λt.λf.f if e 1 then e

More information

II (No.2) 2 4,.. (1) (cm) (2) (cm) , (

II (No.2) 2 4,.. (1) (cm) (2) (cm) , ( II (No.1) 1 x 1, x 2,..., x µ = 1 V = 1 k=1 x k (x k µ) 2 k=1 σ = V. V = σ 2 = 1 x 2 k µ 2 k=1 1 µ, V σ. (1) 4, 7, 3, 1, 9, 6 (2) 14, 17, 13, 11, 19, 16 (3) 12, 21, 9, 3, 27, 18 (4) 27.2, 29.3, 29.1, 26.0,

More information

ML 演習 第 4 回

ML 演習 第 4 回 ML 演習第 4 回 おおいわ Mar 6, 2003 今回の内容 補足 Ocaml のモジュールシステム structure signature functor Ocaml コンパイラの利用 2 識別子について 利用可能文字 先頭文字 : A~Z, a~z, _ ( 小文字扱い ) 2 文字目以降 : A~Z, a~z, 0~9, _, 先頭の文字の case で 2 つに区別 小文字 : 変数,

More information

r07.dvi

r07.dvi 19 7 ( ) 2019.4.20 1 1.1 (data structure ( (dynamic data structure 1 malloc C free C (garbage collection GC C GC(conservative GC 2 1.2 data next p 3 5 7 9 p 3 5 7 9 p 3 5 7 9 1 1: (single linked list 1

More information

( ) ( ) lex LL(1) LL(1)

( ) ( ) lex LL(1) LL(1) () () lex LL(1) LL(1) http://www.cs.info.mie-u.ac.jp/~toshi/lectures/compiler/ 29 5 14 1 1 () / (front end) (back end) (phase) (pass) 1 2 1 () () var left, right; fun int main() { left = 0; right = 10;

More information

ohp07.dvi

ohp07.dvi 19 7 ( ) 2019.4.20 1 (data structure) ( ) (dynamic data structure) 1 malloc C free 1 (static data structure) 2 (2) C (garbage collection GC) C GC(conservative GC) 2 2 conservative GC 3 data next p 3 5

More information

r3.dvi

r3.dvi / 94 2 (Lisp ) 3 ( ) 1994.5.16,1994.6.15 1 cons cons 2 >(cons a b) (A. B).? Lisp (S ) cons 2 car cdr n A B C D nil = (A B C D) nil nil A D E = (A (B C) D E) B C E = (A B C D. E) A B C D B = (A. B) A nil.

More information

double float

double float 2015 3 13 1 2 2 3 2.1.......................... 3 2.2............................. 3 3 4 3.1............................... 4 3.2 double float......................... 5 3.3 main.......................

More information

Clipboard

Clipboard OCaml はじめの一歩 First Step to OCaml 小笠原啓 ( 有 )IT プランニング デモンストレーション DownDown(graphicsモジュールを使った簡単なプログラム ) Amthing(2Dベクトル描画ライブラリCairoを呼び出しています ) Unison(lablgtkを使っています ) ChartNaviPrime( サーバーサイドで OCaml 製 CGI やデーモンが

More information

O1-1 O1-2 O1-3 O1-4 O1-5 O1-6

O1-1 O1-2 O1-3 O1-4 O1-5 O1-6 O1-1 O1-2 O1-3 O1-4 O1-5 O1-6 O1-7 O1-8 O1-9 O1-10 O1-11 O1-12 O1-13 O1-14 O1-15 O1-16 O1-17 O1-18 O1-19 O1-20 O1-21 O1-22 O1-23 O1-24 O1-25 O1-26 O1-27 O1-28 O1-29 O1-30 O1-31 O1-32 O1-33 O1-34 O1-35

More information

Ver.1.0.1-1512 1. 03 2. 04 3. 05 05 4. 06 07 5. 08 6. 09 10 11 12 14 7. 19 2 1. Plus / 3 2. 1 4 3. Plus 5 4. FX 6 4. 7 5. 1 200 3 8 6. 38 25 16 9 6. 10 6. 11 6. 38 / 12 6. 13 6. 25 14 6. 0 359 15 6. 3

More information

untitled

untitled ( 9:: 3:6: (k 3 45 k F m tan 45 k 45 k F m tan S S F m tan( 6.8k tan k F m ( + k tan 373 S S + Σ Σ 3 + Σ os( sin( + Σ sin( os( + sin( os( p z ( γ z + K pzdz γ + K γ K + γ + 9 ( 9 (+ sin( sin { 9 ( } 4

More information

1. A0 A B A0 A : A1,...,A5 B : B1,...,B12 2. 5 3. 4. 5. A0 (1) A, B A B f K K A ϕ 1, ϕ 2 f ϕ 1 = f ϕ 2 ϕ 1 = ϕ 2 (2) N A 1, A 2, A 3,... N A n X N n X N, A n N n=1 1 A1 d (d 2) A (, k A k = O), A O. f

More information

untitled

untitled II yacc 005 : 1, 1 1 1 %{ int lineno=0; 3 int wordno=0; 4 int charno=0; 5 6 %} 7 8 %% 9 [ \t]+ { charno+=strlen(yytext); } 10 "\n" { lineno++; charno++; } 11 [^ \t\n]+ { wordno++; charno+=strlen(yytext);}

More information

Condition DAQ condition condition 2 3 XML key value

Condition DAQ condition condition 2 3 XML key value Condition DAQ condition 2009 6 10 2009 7 2 2009 7 3 2010 8 3 1 2 2 condition 2 3 XML key value 3 4 4 4.1............................. 5 4.2...................... 5 5 6 6 Makefile 7 7 9 7.1 Condition.h.............................

More information

yacc.dvi

yacc.dvi 2017 c 8 Yacc Mini-C C/C++, yacc, Mini-C, run,, Mini-C 81 Yacc Yacc, 1, 2 ( ), while ::= "while" "(" ")" while yacc 1: st while : lex KW WHILE lex LPAREN expression lex RPAREN statement 2: 3: $$ = new

More information

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

1. A0 A B A0 A : A1,...,A5 B : B1,...,B 1. A0 A B A0 A : A1,...,A5 B : B1,...,B12 2. 3. 4. 5. A0 A B f : A B 4 (i) f (ii) f (iii) C 2 g, h: C A f g = f h g = h (iv) C 2 g, h: B C g f = h f g = h 4 (1) (i) (iii) (2) (iii) (i) (3) (ii) (iv) (4)

More information

shift/reset [13] 2 shift / reset shift reset k call/cc reset shift k shift (...) k 1 + shift(fun k -> 2 * (k 3)) k 2 * (1 + 3) 8 reset shift reset (..

shift/reset [13] 2 shift / reset shift reset k call/cc reset shift k shift (...) k 1 + shift(fun k -> 2 * (k 3)) k 2 * (1 + 3) 8 reset shift reset (.. arisa@pllab.is.ocha.ac.jp asai@is.ocha.ac.jp shift / reset CPS shift / reset CPS CPS 1 [3, 5] goto try/catch raise call/cc [17] control/prompt [8], shift/reset [5] control/prompt, shift/reset call/cc (continuationpassing

More information

kyoto.gby

kyoto.gby Haskell 2013.5.24 1 2 1988 B4 Sun 1992 3 Unix Magazine Unix Magazine UNIX RFC FYI (For Your Information) 4 IP PEM (Privacy Enhanced Mail) WIDE Project mh-e PEM 5 6 Unix Magazine PGP PGP 1 7 Mew (MIME)

More information

II 3 yacc (2) 2005 : Yacc 0 ~nakai/ipp2 1 C main main 1 NULL NULL for 2 (a) Yacc 2 (b) 2 3 y

II 3 yacc (2) 2005 : Yacc 0 ~nakai/ipp2 1 C main main 1 NULL NULL for 2 (a) Yacc 2 (b) 2 3 y II 3 yacc (2) 2005 : Yacc 0 ~nakai/ipp2 1 C 1 6 9 1 main main 1 NULL NULL 1 15 23 25 48 26 30 32 36 38 43 45 47 50 52 for 2 (a) 2 2 1 Yacc 2 (b) 2 3 yytext tmp2 ("") tmp2->next->word tmp2 yytext tmp2->next->word

More information

構造化プログラミングと データ抽象

構造化プログラミングと データ抽象 計算の理論 後半第 3 回 λ 計算と型システム 本日の内容 λ 計算の表現力 ( 前回の復習 ) データの表現 不動点演算子と再帰 λ 計算の重要な性質 チャーチ ロッサー性 簡約戦略 型付き λ 計算 ブール値 組 ブール値と組の表現 true, false を受け取り 対応する要素を返す関数 として表現 T = λt.λf.t F = λt.λf.f if e 1 then e 2 else

More information

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

VDM-SL VDM VDM-SL Toolbox VDM++ Toolbox 1 VDM-SL VDM++ Web bool VDM-SL VDM++ 23 6 28 VDM-SL Toolbox VDM++ Toolbox 1 VDM-SL VDM++ Web 2 1 3 1.1............................................... 3 1.1.1 bool......................................... 3 1.1.2 real rat int

More information

ohp07.dvi

ohp07.dvi 17 7 (2) 2017.9.13 1 BNF BNF ( ) ( ) 0 ( ) + 1 ( ) ( ) [ ] BNF BNF BNF prog ::= ( stat ) stat ::= ident = expr ; read ident ; print expr ; if ( expr ) stat while ( expr ) stat { prog expr ::= term ( +

More information

1 911 9001030 9:00 A B C D E F G H I J K L M 1A0900 1B0900 1C0900 1D0900 1E0900 1F0900 1G0900 1H0900 1I0900 1J0900 1K0900 1L0900 1M0900 9:15 1A0915 1B0915 1C0915 1D0915 1E0915 1F0915 1G0915 1H0915 1I0915

More information

2

2 Haskell ( ) kazu@iij.ad.jp 1 2 Blub Paul Graham http://practical-scheme.net/trans/beating-the-averages-j.html Blub Blub Blub Blub 3 Haskell Sebastian Sylvan http://www.haskell.org/haskellwiki/why_haskell_matters...

More information

mstrcpy char *mstrcpy(const char *src); mstrcpy malloc (main free ) stdio.h fgets char *fgets(char *s, int size, FILE *stream); s size ( )

mstrcpy char *mstrcpy(const char *src); mstrcpy malloc (main free ) stdio.h fgets char *fgets(char *s, int size, FILE *stream); s size ( ) 2008 3 10 1 mstrcpy char *mstrcpy(const char *src); mstrcpy malloc (main free ) stdio.h fgets char *fgets(char *s, int size, FILE *stream); s size ( ) stream FILE ( man ) 40 ( ) %./a.out String : test

More information

ML 演習 第 4 回

ML 演習 第 4 回 ML 演習第 4 回 佐藤春旗, 山下諒蔵, 前田俊行 2006/06/20 ICFP Programming Contest 過去の O'Caml プログラムの実績 1998: 2 位 (ENS Camlist, France) 1999: 1 位 (Camls R Us, O'Caml 作者グループ ) 2000: 1 位 (PLClub, U-Penn, 米澤研住井, 細谷参加 ) 2 位 (Camls

More information

平成 28 年度 ( 第 38 回 ) 数学入門公開講座テキスト ( 京都大学数理解析研究所, 平成 ~8 28 月年 48 日開催月 1 日 semantics FB 1 x, y, z,... FB 1. FB (Boolean) Functional

平成 28 年度 ( 第 38 回 ) 数学入門公開講座テキスト ( 京都大学数理解析研究所, 平成 ~8 28 月年 48 日開催月 1 日 semantics FB 1 x, y, z,... FB 1. FB (Boolean) Functional 1 1.1 semantics F 1 x, y, z,... F 1. F 38 2016 9 1 (oolean) Functional 2. T F F 3. P F (not P ) F 4. P 1 P 2 F (P 1 and P 2 ) F 5. x P 1 P 2 F (let x be P 1 in P 2 ) F 6. F syntax F (let x be (T and y)

More information

( ) ( ) 30 ( ) 27 [1] p LIFO(last in first out, ) (push) (pup) 1

( ) ( ) 30 ( ) 27 [1] p LIFO(last in first out, ) (push) (pup) 1 () 2006 2 27 1 10 23 () 30 () 27 [1] p.97252 7 2 2.1 2.1.1 1 LIFO(last in first out, ) (push) (pup) 1 1: 2.1.2 1 List 4-1(p.100) stack[] stack top 1 2 (push) (pop) 1 2 void stack push(double val) val stack

More information

SML#³«È¯ºÇÁ°Àþ

SML#³«È¯ºÇÁ°Àþ SML# 2011 in Tokyo, 2011/09/17 1 / 34 SML# 2011 in Tokyo, 2011/09/17 1 / 34 SML# 2011 in Tokyo, 2011/09/17 1 / 34 SML# ML 1993 SML# of Kansai 2003 e-society JAIST 2006 SML# 0.10 2011 9 SML# 0.90 2 / 34

More information

test.gby

test.gby Beautiful Programming Language and Beautiful Testing 1 Haskeller Haskeller 2 Haskeller (Doctest QuickCheck ) github 3 Haskeller 4 Haskell Platform 2011.4.0.0 Glasgow Haskell Compiler + 23 19 8 5 10 5 Q)

More information

1 12 *1 *2 (1991) (1992) (2002) (1991) (1992) (2002) 13 (1991) (1992) (2002) *1 (2003) *2 (1997) 1

1 12 *1 *2 (1991) (1992) (2002) (1991) (1992) (2002) 13 (1991) (1992) (2002) *1 (2003) *2 (1997) 1 2005 1 1991 1996 5 i 1 12 *1 *2 (1991) (1992) (2002) (1991) (1992) (2002) 13 (1991) (1992) (2002) *1 (2003) *2 (1997) 1 2 13 *3 *4 200 1 14 2 250m :64.3km 457mm :76.4km 200 1 548mm 16 9 12 589 13 8 50m

More information

untitled

untitled PGF 17 6 1 11 1 12 1 2 21 2 22 2 23 3 1 3 1 3 2 3 3 3 4 3 5 4 6 4 2 4 1 4 2 4 3 4 4 4 5 5 3 5 1 5 2 5 5 5 5 4 5 1 5 2 5 3 6 5 6 1 6 2 6 6 6 24 7 1 7 1 7 2 7 3 7 4 8 2 8 1 8 2 8 3 9 4 9 5 9 6 9 3 9 1 9

More information

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

プログラミング言語 8   字句解析器(lexer)と構文解析器(parser) 8 (lexer) (parser) 1 / 73 (lexer, tokenizer) (parser) Web Page (HTML XML) CSV, SVG,...... config file... ( )! 2 / 73 1 1 OCaml : ocamllex ocamlyacc 2 Python : ply 2! 3 / 73 ( ) 字句解析器 構文解析器 ご注文はうさぎさんですか?

More information

10 117 5 1 121841 4 15 12 7 27 12 6 31856 8 21 1983-2 - 321899 12 21656 2 45 9 2 131816 4 91812 11 20 1887 461971 11 3 2 161703 11 13 98 3 16201700-3 - 2 35 6 7 8 9 12 13 12 481973 12 2 571982 161703 11

More information

0.45m1.00m 1.00m 1.00m 0.33m 0.33m 0.33m 0.45m 1.00m 2

0.45m1.00m 1.00m 1.00m 0.33m 0.33m 0.33m 0.45m 1.00m 2 24 11 10 24 12 10 30 1 0.45m1.00m 1.00m 1.00m 0.33m 0.33m 0.33m 0.45m 1.00m 2 23% 29% 71% 67% 6% 4% n=1525 n=1137 6% +6% -4% -2% 21% 30% 5% 35% 6% 6% 11% 40% 37% 36 172 166 371 213 226 177 54 382 704 216

More information

listings-ext

listings-ext (6) Python (2) ( ) ohsaki@kwansei.ac.jp 5 Python (2) 1 5.1 (statement)........................... 1 5.2 (scope)......................... 11 5.3 (subroutine).................... 14 5 Python (2) Python 5.1

More information

exec.dvi

exec.dvi 2018 c 6, Mini-C C++ 6211 611, 61, print,,, (run ),,, (int ), 7, x, x "a" 3 "b" 4 "x" 10 (, ), x STL map 1 + 2, 1 2,, x = ;, 1, 2 x { 1 ; 2 ; ; m, if ( ) { 1 else { 2, 1,, 2 0, 1, 3 0, 2,,, main 6 1 ,,

More information

コンピュータ概論

コンピュータ概論 4.1 For Check Point 1. For 2. 4.1.1 For (For) For = To Step (Next) 4.1.1 Next 4.1.1 4.1.2 1 i 10 For Next Cells(i,1) Cells(1, 1) Cells(2, 1) Cells(10, 1) 4.1.2 50 1. 2 1 10 3. 0 360 10 sin() 4.1.2 For

More information

I void* School of Information Science, Japan Advanced Institute of Science and Technology

I void* School of Information Science, Japan Advanced Institute of Science and Technology I117 25 void* School of Information Science, Japan Advanced Institute of Science and Technology sdict ( ) idict ; long long double void* Japan Advanced Institute of Science and Technology 2008 1-2 1 idict

More information

K227 Java 2

K227 Java 2 1 K227 Java 2 3 4 5 6 Java 7 class Sample1 { public static void main (String args[]) { System.out.println( Java! ); } } 8 > javac Sample1.java 9 10 > java Sample1 Java 11 12 13 http://java.sun.com/j2se/1.5.0/ja/download.html

More information

untitled

untitled C L C L 4.5m 3.0m 10% 25% 50% 90% 75% 50% N N N 90% 90% 10% 10% 100 100 10 10 10% 10% :49kN :17 :17kN CBR CBR CBR 5 3,000 / 3,000 /mm /mm 1.2mm 89dB 190dB 3,000 3,000 /mm 20% 20%

More information

連載 構文解析器結合子 山下伸夫 (( 株 ) タイムインターメディア ) 文字列の分解 1 1 Haskell lines Prelude lines :: String -> [String] lines "" = [] lines s = let (l,s'

連載 構文解析器結合子 山下伸夫 (( 株 ) タイムインターメディア ) 文字列の分解 1 1 Haskell lines Prelude lines :: String -> [String] lines  = [] lines s = let (l,s' 連載 構文解析器結合子 山下伸夫 (( 株 ) タイムインターメディア ) nobsun@sampou.org 文字列の分解 1 1 Haskell lines Prelude lines :: String -> [String] lines "" = [] lines s = let (l,s') = break ('\n'==) s in l : case s' of [] -> [] (_:s'')

More information

monad.gby

monad.gby 2012.11.18 1 1 2 2 DSL 3 4 Q) A) 5 Q) A) 6 7 8 Haskell 9 10 Parser data Parser a = Parser (String -> [(a,string)]) Parser pwrap :: a -> Parser a pwrap v = Parser $ \inp -> [(v,inp)] Parser pbind :: Parser

More information

lexex.dvi

lexex.dvi (2018, c ) http://istksckwanseiacjp/ ishiura/cpl/ 4 41 1 mini-c lexc,, 2 testlexc, lexc mini-c 1 ( ) mini-c ( ) (int, char, if, else, while, return 6 ) ( ) (+, -, *, /, %, &, =, ==,!=, >, >=,

More information

1 1.1 C 2 1 double a[ ][ ]; 1 3x x3 ( ) malloc() malloc 2 #include <stdio.h> #include

1 1.1 C 2 1 double a[ ][ ]; 1 3x x3 ( ) malloc() malloc 2 #include <stdio.h> #include 1 1.1 C 2 1 double a[ ][ ]; 1 3x3 0 1 3x3 ( ) 0.240 0.143 0.339 0.191 0.341 0.477 0.412 0.003 0.921 1.2 malloc() malloc 2 #include #include #include enum LENGTH = 10 ; int

More information

…J…−†[†E…n…‘†[…hfi¯„^‚ΛžfiüŒå

…J…−†[†E…n…‘†[…hfi¯„^‚ΛžfiüŒå takuro.onishi@gmail.com II 2009 6 11 [A] D B A B A B A B DVD y = 2x + 5 x = 3 y = 11 x = 5 y = 15. Google Web (2 + 3) 5 25 2 3 5 25 Windows Media Player Media Player (typed lambda calculus) (computer

More information

浜松医科大学紀要

浜松医科大学紀要 On the Statistical Bias Found in the Horse Racing Data (1) Akio NODA Mathematics Abstract: The purpose of the present paper is to report what type of statistical bias the author has found in the horse

More information

untitled

untitled C -1 - -2 - concept lecture keywords FILE, fopen, fclose, fscanf, fprintf, EOF, r w a, typedef gifts.dat Yt JZK-3 Jizake tsumeawase 45 BSP-15 Body soap set 3 BT-2 Bath towel set 25 TEA-2 Koutya

More information

Mathematical Logic I 12 Contents I Zorn

Mathematical Logic I 12 Contents I Zorn Mathematical Logic I 12 Contents I 2 1 3 1.1............................. 3 1.2.......................... 5 1.3 Zorn.................. 5 2 6 2.1.............................. 6 2.2..............................

More information