From fe38d7ca73bc552ea4e46ec24ce668030698e2f5 Mon Sep 17 00:00:00 2001 From: Jed Barber Date: Mon, 10 Mar 2014 21:19:35 +1100 Subject: Added support for the e Unlambda builtin --- Unlambda/Interpreter.hs | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/Unlambda/Interpreter.hs b/Unlambda/Interpreter.hs index 170b2a7..e5a442b 100644 --- a/Unlambda/Interpreter.hs +++ b/Unlambda/Interpreter.hs @@ -3,13 +3,24 @@ module Unlambda.Interpreter ( ) where +import Control.Exception( Exception(..), Handler(..), throw, catches ) +import Data.Typeable import Unlambda.Parser +data UnlambdaException = UnlambdaException { endTerm :: UnlambdaTerm } + deriving (Show, Typeable) + +instance Control.Exception.Exception UnlambdaException + + + unlambda :: UnlambdaTerm -> IO UnlambdaTerm -unlambda term = eval term +unlambda term = + catches (eval term) + [ Handler ((\e -> return (endTerm e)) :: UnlambdaException -> IO UnlambdaTerm) ] @@ -56,7 +67,9 @@ apply firstTerm secondTerm = R -> putChar '\n' >> eval secondTerm - E -> return I --placeholder + E -> do + t <- eval secondTerm + throw (UnlambdaException t) Reed -> return I --placeholder -- cgit