unlambda 0.1 → 0.1.2
raw patch · 3 files changed
+19/−12 lines, 3 filesdep ~base
Dependency ranges changed: base
Files
- Language/Unlambda.hs +5/−6
- Main.hs +6/−2
- unlambda.cabal +8/−4
Language/Unlambda.hs view
@@ -1,5 +1,3 @@-{-# OPTIONS -fglasgow-exts #-}- {- Uses pattern guards @@ -51,7 +49,8 @@ ------------------------------------------------------------------------ -- Printing -instance Show Exp where showsPrec _ e = sh e+instance Show Exp where+ showsPrec _ = sh sh :: Exp -> String -> String sh (App x y) = showChar '`' . sh x . sh y@@ -125,14 +124,14 @@ apply (S2 x y) z = eval (App (App x z) (App y z)) apply I x = return x apply V _ = return V-apply C x = callCC (\c -> apply x (Cont c))+apply C x = callCC (apply x . Cont) apply (Cont c) x = throw c x apply D x = return x apply (D1 e) x = do f <- eval e; apply f x apply (Dot c) x = step >> io (putChar c) >> return x apply E x = exit x apply At f = do- dat <- io $ catch (getChar >>= return . Just) (const $ return Nothing)+ dat <- io $ catch (fmap Just getChar) (const $ return Nothing) setCurrentChar dat apply f (case dat of Nothing -> V ; Just _ -> I) apply (Ques c) f = do@@ -140,5 +139,5 @@ apply f (if cur == Just c then I else V) apply Pipe f = do cur <- currentChar- apply f (case cur of Nothing -> V ; Just c -> (Dot c))+ apply f (case cur of Nothing -> V ; Just c -> Dot c) apply (App _ _) _ = error "Unknown application"
Main.hs view
@@ -5,11 +5,15 @@ -- A time- and output-limited unlambda import System.Posix.Resource-import Data.Char-import System.IO+import Data.Char (toLower)+import System.IO (hGetChar, hGetLine, stdin, Handle()) import Language.Unlambda +{- WARNING: There is no way this is actually enough sandboxing (mueval has to do+a heck of a lot more to safely valuate expressions and not all of it+involves libraries), but since no one seems to be attacking via `unlambda`+we'll leave this be. -} main :: IO Exp main = (setResourceLimit ResourceCPUTime $ ResourceLimits (ResourceLimit 5) (ResourceLimit 5)) >> run
unlambda.cabal view
@@ -1,5 +1,5 @@ name: unlambda-version: 0.1+version: 0.1.2 license: GPL license-file: LICENSE@@ -14,17 +14,21 @@ written in the pure, lazy, functional language Haskell. build-type: Simple-Cabal-Version: >= 1.2+Cabal-Version: >= 1.6 tested-with: GHC==6.8.2 +source-repository head+ type: darcs+ location: http://code.haskell.org/lambdabot+ executable unlambda main-is: Main.hs- build-depends: base>3, unix+ build-depends: base>3 && <5, unix library exposed-modules: Language.Unlambda - build-depends: base, array, mtl+ build-depends: base>3 && <5, array, mtl ghc-options: -Wall ghc-prof-options: -prof -auto-all