diff options
author | Jed Barber <jjbarber@y7mail.com> | 2014-03-09 23:35:26 +1100 |
---|---|---|
committer | Jed Barber <jjbarber@y7mail.com> | 2014-03-09 23:36:17 +1100 |
commit | 7e70b177b76d632dc2975e17e14321e8bc3387d8 (patch) | |
tree | bdda54478913bdd946dfed5dcbdb4120bc156518 /Unlambda | |
parent | 34354ba50c1cc9ed22bd3b8bc1881ce4483e6633 (diff) |
Added Unlambda interpreter, currently without support for C,E,@,|,?
Diffstat (limited to 'Unlambda')
-rw-r--r-- | Unlambda/Interpreter.hs | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/Unlambda/Interpreter.hs b/Unlambda/Interpreter.hs new file mode 100644 index 0000000..170b2a7 --- /dev/null +++ b/Unlambda/Interpreter.hs @@ -0,0 +1,68 @@ +module Unlambda.Interpreter ( + unlambda + ) where + + +import Unlambda.Parser + + + + +unlambda :: UnlambdaTerm -> IO UnlambdaTerm +unlambda term = eval term + + + +eval :: UnlambdaTerm -> IO UnlambdaTerm +eval term = + case term of + App f x -> do + t <- eval f + apply t x + _ -> return term + + + +apply :: UnlambdaTerm -> UnlambdaTerm -> IO UnlambdaTerm +apply firstTerm secondTerm = + case firstTerm of + K -> eval secondTerm >>= return . Kpartial + + Kpartial x -> eval secondTerm >> return x + + S -> eval secondTerm >>= return . Spartial + + Spartial x -> eval secondTerm >>= return . (Sapp x) + + Sapp x y -> do + z <- eval secondTerm + result <- eval (App (App x z) (App y z)) + return result + + I -> eval secondTerm + + V -> eval secondTerm >> return V + + C -> return I --placeholder + + D -> return (Promise secondTerm) + + Promise x -> do + y <- eval secondTerm + result <- eval (App x y) + return result + + Dot c -> putChar c >> eval secondTerm + + R -> putChar '\n' >> eval secondTerm + + E -> return I --placeholder + + Reed -> return I --placeholder + + Bar -> return I --placeholder + + Compare c -> return I --placeholder + + Continuation cont -> return I --placeholder + |