language: Ocaml (ocamlopt 3.10.2)
date: 249 days 17 hours ago
link:
visibility: public
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
exception Undefined
;;
type direction = R | L 
;; 
type stat = T | F
;;
type tape = {
   data : int array ;
   pos  : int ;
} 
;;
let rec turing state delta tape =
   try
      let mem = match tape.data.(tape.pos) with
           1 -> T
         | 0 -> F 
         | _ -> raise Undefined in
      let ins = List.find ( fun x -> match x with (state,mem,_,_,_) -> true ) delta in
      match ins with
         (v,w,x,y,z) -> tape.data.(tape.pos) <- ( match x with T -> 1 | F -> 0 ) ;
                        turing y delta 
                        { 
                           data = tape.data ; 
                           pos = tape.pos + ( match z with R -> 1 | L -> -1 ) 
                        } ;  
   with
      _ -> ()
;;
 
let op = [
   (0,F,T,0,R);
   (0,T,F,1,R);
]
;;
 
let tp = {
   data = Array.create 10 0 ;
   pos  = 0 ;
}
;;
 
(* 実行 *)
 
let () = turing 0 op tp
;;
(* 結果を出力 *)
let () = Array.iter (fun x -> print_int x ) tp.data
;;
File "prog.ml", line 14, characters 10-13:
Warning Y: unused variable mem.