Type inference

Untyped lambda calculus

Mogensen's encoding

Efficient Self-Interpretation in Lambda Calculus, Mogensen

-- Predefined:
S  := λn f x.f(n f x)
1  := λf x.f x
Y  := λf.(λx.f(x x)) (λx.f(x x))
R  := λ m . RR m (λa b . b)
E  := Y (λe m.m (λx.x) (λm n.(e m)(e n)) (λm v.e (m v)))
P  := Y (λp m. (λx.x (λv.p (λa b c.b m (v (λa b.b))))m))
RR := Y (λr m.m (λx.x)
         (λm n.
          (r m)
           (λa b.a)
            (r n))
             (λm.(λg x.x g
              (λa b c.c
               (λw.g (P
                (λa b c.a w))
                 (λa b.b))))
                  (λv.r (m v))))

-- Examples:
E (quote (S (S (S 1))))        -- (1) Self-interpreter demo
R (quote (S (S (S 1))))        -- (2) Self-reducer demo

-- Result (1)
λv v1.v (v (v (v v1)))

-- Result (2)
λa b c . c
 (λw a b c . c
  (λw1 a b c . b
   (λa b c . a w)
    (λa b c . b
     (λa b c . a w)
      (λa b c . b
       (λa b c . a w)
        (λa b c . b
         (λa b c . a w)
          (λa b c . a w1))))))

Quote

Shallow encoding

Factorial

Last updated

Was this helpful?