summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Unlambda/Interpreter.hs17
1 files 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