From a23c312042d1ea36eedc73572747397a009b8a7f Mon Sep 17 00:00:00 2001 From: Chris Allen Date: Sun, 20 Jul 2014 00:19:40 -0500 Subject: [PATCH] added code --- dialogues.md | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/dialogues.md b/dialogues.md index 5bbd19e..4843710 100644 --- a/dialogues.md +++ b/dialogues.md @@ -100,3 +100,30 @@ doubleEveryOther list = reverse .doubleEveryOtherForward . reverse $ list 05:16 < ReinH> No, it's probably not. 05:16 < ReinH> But other things are pretty much generalizations of that ``` + +```haskell +type Variable = String + +data Expression = Reference Variable + | Lambda Variable Expression + | Combination Expression Expression + +type Kvariable = String + +data Uatom = Procedure Variable Kvariable Call + | Ureference Variable + +data Katom = Continuation Variable Call + | Kreference Variable + | Absorb + +data Call = Application Uatom Uatom Katom + | Invocation Katom Uatom + +cpsTransform :: Expression -> Katom -> Call +cpsTransform (Reference r) k = Invocation k $ Ureference r +cpsTransform (Lambda p b) k = Invocation k $ Procedure p + "k" $ + cpsTransform b $ Kreference "k" +cpsTransform (Combination a b) k = cpsTransform a $ Continuation "v" $ cpsTransform b k +```