abnv,
@abnv@fantastic.earth avatar

I ported @mattmight’s CPS conversion code (https://matt.might.net/articles/cps-conversion/) to #Haskell and after some fighting with the type system, it worked! To make the interpreters work with the Cont monad, I had to remove recursive lets and hence, functions being able to call themselves recursively, but the rest works fine.

The attached images show the conversion of the Fibonacci function into the CPS version.

#Programming #ProgramingLanguages #Compilers #PLT

CPS version of Fibonacci function in Lisp: (let ([fib (λ (n k0) (let ([fib' (λ (n f k1) ((λ (k2) ((λ (v3) (if v3 (k2 0) ((λ (k4) ((λ (v5) (if v5 (k4 1) ((λ (v9) (f v9 f (λ (v6) ((λ (v8) (f v8 f (λ (v7) (k4 (+ v6 v7))))) (- n 2))))) (- n 1)))) (= n 1))) k2))) (= n 0))) k1))]) (fib' n fib' k0)))]) (fib 10 return))

abnv,
@abnv@fantastic.earth avatar
rml,

@abnv his blog is my goto for learning about program transformations

abnv,
@abnv@fantastic.earth avatar

@rml Mine too, for years.

  • All
  • Subscribed
  • Moderated
  • Favorites
  • programming
  • DreamBathrooms
  • everett
  • osvaldo12
  • magazineikmin
  • thenastyranch
  • rosin
  • tester
  • Youngstown
  • Durango
  • slotface
  • ngwrru68w68
  • kavyap
  • mdbf
  • InstantRegret
  • JUstTest
  • ethstaker
  • GTA5RPClips
  • tacticalgear
  • normalnudes
  • Leos
  • modclub
  • khanakhh
  • cubers
  • cisconetworking
  • megavids
  • anitta
  • provamag3
  • lostlight
  • All magazines