forked from luqui/vatican
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinterps.pul
42 lines (29 loc) · 1.03 KB
/
interps.pul
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
\primzero primsucc ->
(\interp ->
interp (\f -> f) (\f x -> f x) (\x -> x)
) (quote ((\let ->
-- error
let ((\x -> x x) (\x -> x x)) \error ->
-- church numerals
let (\f x -> x) \zero ->
let (\n f x -> f (n f x)) \succ ->
-- scott lists
let (\n c -> n) \nil ->
let (\x xs -> \n c -> c x xs) \cons ->
let (\l -> l error (\x xs -> x)) \head ->
let (\l -> l error (\x xs -> xs)) \tail ->
let (\xs n -> head (n tail xs)) \index ->
-- scott debruijn
let (\f -> \l a v -> l f) \fun ->
let (\t u -> \l a v -> a t u) \app ->
let (\n -> \l a v -> v n) \var ->
-- recursion
let (\f -> (\x -> x x) (\x -> f (x x))) \fix ->
-- interpreter
let (fix (\interp env term -> term (\body -> \x -> interp (cons x env) body)
(\fun arg -> interp env fun (interp env arg))
(\var -> index env var)) nil)
\interpreter ->
interpreter (fun (fun (var (succ zero)))) primzero error
) (\def body -> body def)))
-- vim: ft=haskell :