Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Lambda interpreter in PHP

Lambda interpreter in PHP

This talk is about creating a lambda interpreter in PHP

Exemple code associated to this talk (LambdaFlow)

https://github.com/darkwood-com/flow

Article associated to this talk

https://blog.darkwood.com/article/create-a-lambda-interpreter-in-php

Video associated to this talk

https://www.youtube.com/watch?v=TsVHdYLQorM

Mathieu Ledru

March 21, 2025
Tweet

More Decks by Mathieu Ledru

Other Decks in Programming

Transcript

  1. Alonzo Church ( 1903 - 1995 ) Inventor of Lambda

    Calculus @matyo91 @matyo91 20-03-2025
  2. λ x . x + 1 ( λ x .

    x + 1 ) ( 5 ) = 5 + 1 = 6 @matyo91 @matyo91 20-03-2025 X X + 1
  3. λ x . λ y . x+y ( λ x

    . λ y . x+y ) ( 5 , 6 ) = 5 + 6 = 11 @matyo91 @matyo91 20-03-2025 X X + Y Y
  4. There are variables. We got a way to build functions.

    We can apply functions to each others by providing elements of the language itself. All derivatives of lambda calculus language is something defined in terms of this definition. Lambda Calculus @matyo91 20-03-2025 @matyo91
  5. Combinator @matyo91 @matyo91 20-03-2025 Pol Dellaiera https://github.com/loophp/combinator Name Alias Haskell

    Lambda calculus JS like A Apply $ λab.ab a => b => a(b) B Bluebird . λabc.a(bc) a => b => c => a(b(c)) Blackbird Blackbird ... λabcd.a(bcd) a => b => c => => d => a(b(c) (d)) C Cardinal flip λabc.acb a => b => c => a(c)(b) I Idiot id λa.a a => a
  6. Combinator @matyo91 @matyo91 20-03-2025 Name Alias Haskell Lambda calculus JS

    like K Kestrel const λab.a a => b => a Psi on λabcd.a(bc)(bd) a => b => c => d => a(b(c)) (b(d)) Q Queer (##) λabc.b(ac) a => b => c => b(a(c)) S Starling <*> λabc.ac(bc) a => b => c => a(c)(b(c)) T Thrush (&) λab.ba a => b => b(a)
  7. @matyo91 20-03-2025 @matyo91 Lambda-PHP (bonus) Krivine machine: Alternate interpreter that

    uses de-bruijn indices (M N, S, E) → (M, (S,(N,E)), E) (λM, (S,N), E) → (M, S, (E,N)) (i+1, S, (E,N)) → (i, S, E) (0, S, (E1,(M,E2))) → (M, S, E2) Binary lambda calculus: Allows encoding lambda calculus programs in binary form which produces extremely small programs. This also defines an I/O mechanism.
  8. <expression> := <name> | <function> | <application> <function> := λ

    <name>.<expression> <application> := <expression><expression> @matyo91 20-03-2025 @matyo91 Language Introduction to the Lambda Calculus https://personal.utdallas.edu/~gupta/ courses/apl/lambda.pdf
  9. @matyo91 20-03-2025 @matyo91 Compiler Transformation Code Generation Parsing Tokens AST

    The Super Tiny Compiler https://github.com/jamiebuilds/the- super-tiny-compiler
  10. Hello! I Am Mathieu Ledru You can contact me at

    @matyo91 20-03-2025 @matyo91 Thanks! Any questions?