Skip to content

Instantly share code, notes, and snippets.

@nakamura-to
Created January 8, 2013 12:25
Show Gist options
  • Save nakamura-to/4483335 to your computer and use it in GitHub Desktop.
Save nakamura-to/4483335 to your computer and use it in GitHub Desktop.
チューリングを読む p.126
// .01010101...
type Symbol =
| None
| Str of string
| Num of int
type Op =
| P of Symbol
| R
let tape = Array.create 20 None
let mutable pos = 0
let showTape() =
tape
|> Array.map (function
| None -> " "
| Str x -> x
| Num x -> string x)
|> Array.iter (printf "%s")
let run opList m =
for op in opList do
if pos < tape.Length then
match op with
| P symbol -> tape.[pos] <- symbol
| R -> pos <- pos + 1
if pos < tape.Length then
m()
else
showTape()
let P0 = P(Num 0)
let P1 = P(Num 1)
let rec b() =
match tape.[pos] with
| None -> run [P0; R] c
| otherwise -> failwith <| string otherwise
and c() =
match tape.[pos] with
| None -> run [R] e
| otherwise -> failwith <| string otherwise
and e() =
match tape.[pos] with
| None -> run [P1; R] k
| otherwise -> failwith <| string otherwise
and k() =
match tape.[pos] with
| None -> run [R] b
| otherwise -> failwith <| string otherwise
run [] b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment