summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJed Barber <jjbarber@y7mail.com>2014-03-10 21:19:35 +1100
committerJed Barber <jjbarber@y7mail.com>2014-03-10 21:19:35 +1100
commitfe38d7ca73bc552ea4e46ec24ce668030698e2f5 (patch)
treef2358349a3e2ae26317b104ca48e66717ce9deaa
parent7e70b177b76d632dc2975e17e14321e8bc3387d8 (diff)
Added support for the e Unlambda builtin
-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