graph-rewriting-lambdascope 0.5.10 → 0.5.11
raw patch · 11 files changed
+91/−94 lines, 11 filesdep +indentparserdep +mtldep −IndentParserdep ~GLUTdep ~OpenGLdep ~base
Dependencies added: indentparser, mtl
Dependencies removed: IndentParser
Dependency ranges changed: GLUT, OpenGL, base, graph-rewriting, graph-rewriting-gl, graph-rewriting-layout, graph-rewriting-strategies
Files
- AUTHORS +1/−0
- GL.hs +0/−3
- Rules.hs +0/−2
- Term.hs +64/−65
- examples/WW-beta-saving-0.l +1/−1
- examples/WW-beta-saving-1.l +1/−1
- examples/case/sum.l +0/−5
- examples/levy-1988-p184bottom.l +1/−1
- examples/sum_case.l +4/−0
- examples/vincent-1-ww.l +2/−2
- graph-rewriting-lambdascope.cabal +17/−14
AUTHORS view
@@ -1,2 +1,3 @@ Jan Rochel+Robert Kreuzer Chas Leichner (Google Inc.)
GL.hs view
@@ -22,11 +22,8 @@ Operator {} → sd n : [sd $ rm (alpha ops*x) `mmul` sws | x <- [0..la ops - 1]] where n = Vector2 0 1- w = Vector2 (-1) 0 e = Vector2 1 0 s = Vector2 0 (-1)- sw = Vector2 (-1) (-1)- se = Vector2 1 (-1) la field = toEnum $ length (field node) alpha f = pi/(2*la f)
Rules.hs view
@@ -9,8 +9,6 @@ import GraphRewriting.Graph.Read import GraphRewriting.Graph.Write import Data.List (transpose, elemIndex, delete)-import Control.Applicative-import Data.Monoid import Control.Monad import Data.Maybe (fromJust)
Term.hs view
@@ -2,15 +2,10 @@ module Term where import Prelude.Unicode-import Text.ParserCombinators.Parsec as Parsec- hiding (space, eof, notFollowedBy, anyChar, many, optional, (<|>))-import Text.ParserCombinators.Parsec.IndentParser as Indent-import Text.ParserCombinators.Parsec.Language-import Text.ParserCombinators.Parsec.IndentParser.Token-import qualified Text.ParserCombinators.Parsec.Token as T-import Control.Monad-import Data.Functor-import Control.Applicative+import Text.Parsec+import Control.Monad.Identity+import Text.Parsec.Token (makeTokenParser, GenLanguageDef(..))+import Text.Parsec.IndentParsec -- | The AST of a lambda expression data Λ = A Λ Λ -- ^ application@@ -23,89 +18,93 @@ -- | The LHS of a case expression. Numbers are parsed as strings. data Pattern = Pat {constr ∷ String, vars ∷ [String]} deriving (Show, Eq, Ord) -testParser ∷ IndentParser tok () c → [tok] → c-testParser parser str = either (error ∘ show) id (Indent.parse parser "(null)" str)+type IndentCharParser a = IndentParsec String () a -parse ∷ [Char] → Λ-parse = testParser expression+langDef = LanguageDef { commentStart = "{-"+ , commentEnd = "-}"+ , commentLine = "--"+ , identStart = letter <|> char '_'+ , identLetter = alphaNum <|> char '_'+ , opStart = oneOf "-+/*=<>"+ , opLetter = oneOf "-+/*=<>"+ , reservedNames = ["let", "in", "case", "of"]+ , reservedOpNames = ["=", "->", "→", "."]+ , caseSensitive = False+ , nestedComments = True+ } parseFile ∷ FilePath → IO Λ-parseFile = liftM (either (error ∘ show) id) ∘ Indent.parseFromFile expression+parseFile f = do+ file ← readFile f+ let parseErrorOrExpr = runIdentity $ runGIPT expression () f file+ return $ either (error ∘ show) id parseErrorOrExpr -expression ∷ IndentCharParser st Λ+expression ∷ IndentCharParser Λ expression = flip label "expression" $ letBinding <|> caseExpr <|> application -application ∷ IndentCharParser st Λ+application ∷ IndentCharParser Λ application = foldl1 A <$> many1 (parenthetic <|> abstraction <|> variable <|> numeral) -variable ∷ IndentCharParser st Λ-variable = C <$> (ident <|> operator haskell) <*> pure []+variable ∷ IndentCharParser Λ+variable = C <$> (ident <|> operator tokP) <*> pure [] -numeral ∷ IndentCharParser st Λ+numeral ∷ IndentCharParser Λ numeral = C <$> numeric <*> pure [] -numeric ∷ IndentCharParser st String-numeric = either show show <$> naturalOrFloat haskell+numeric ∷ IndentCharParser String+numeric = either show show <$> naturalOrFloat tokP -parenthetic ∷ IndentCharParser st Λ-parenthetic = parens haskell expression+parenthetic ∷ IndentCharParser Λ+parenthetic = parens tokP expression -tokP ∷ T.TokenParser st-tokP = T.makeTokenParser haskellDef+tokP :: IndentTokenParser String () Identity+tokP = makeTokenParser langDef -caseExpr ∷ IndentCharParser st Λ-caseExpr = flip label "case expression" $- Case <$> (keyword "case" *> expression <* keyword "of") <*> bracesOrBlock tokP patterns+caseExpr ∷ IndentCharParser Λ+caseExpr = flip label "case expression" $ do+ keyword "case"+ Case <$> expression <* keyword "of" <*> blockOf (many1 $ foldedLinesOf pattern) -patterns ∷ IndentCharParser st [(Pattern, Λ)]-patterns = semiOrNewLineSep tokP pattern+arrow ∷ IndentCharParser ()+arrow = reservedOp tokP "→" <|> reservedOp tokP "->" -arrow ∷ IndentCharParser st String-arrow = sym "→" <|> sym "->"+point ∷ IndentCharParser ()+point = reservedOp tokP "." -pattern ∷ IndentCharParser st (Pattern, Λ)-pattern = (,) <$> lhs <*> (arrow *> expression) where- lhs = Pat <$> (ident <|> numeric) <*> many (ident <|> numeric)+pattern ∷ IndentCharParser (Pattern, Λ)+pattern = (,) <$> lhs <*> expression where+ lhs = Pat <$> (ident <|> numeric) <*> manyTill (ident <|> numeric) arrow -lambda ∷ IndentCharParser st String+lambda ∷ IndentCharParser String lambda = sym "λ" <|> sym "\\" -abstraction ∷ IndentCharParser st Λ+abstraction ∷ IndentCharParser Λ abstraction = flip label "abstraction" $- flip (foldr Λ) <$> (lambda *> many1 ident) <*> ((sym "." <|> arrow) *> expression)+ flip (foldr Λ) <$> (lambda *> many1 ident) <*> ((arrow <|> point) *> expression) --- Ugly, but works. Keyword "in" terminates binding blocks and bindings. Allows empty lets-letBinding ∷ IndentCharParser st Λ+letBinding ∷ IndentCharParser Λ letBinding = flip label "let binding" $ do- let parseBindings = do- e ← optionMaybe $ keyword "in" *> expression- case e of- Just je → return ([], Just je)- Nothing → do- (b,e) ← lineFold $ (,) <$> binding <*> (optionMaybe $ keyword "in" *> expression)- case e of- Nothing → do- rec ← optionMaybe parseBindings- case rec of- Nothing → return ([b], Nothing)- Just (bs, me) → return (b:bs, me)- Just je → return ([b], Just je)- (binds, e) ← keyword "let" *> block parseBindings- case e of- Nothing → L binds <$> (keyword "in" *> expression)- Just je → return $ L binds je+ keyword "let"+ try oneLiner <|> multipleBindings where+ oneLiner = do+ b ← binding+ L [b] <$> (keyword "in" *> expression)+ multipleBindings = L <$> blockOf (many1 $ foldedLinesOf binding) <*> (keyword "in" *> expression) -binding ∷ IndentCharParser st (String,Λ)+binding ∷ IndentCharParser (String,Λ) binding = flip label "binding" $ do funct ← ident- rhs ← flip (foldr Λ) <$> many ident <*> (sym "=" *> expression)+ rhs ← flip (foldr Λ) <$> manyTill ident equals <*> expression return (funct, rhs) -keyword ∷ String → IndentCharParser st ()-keyword = reserved haskell+keyword ∷ String → IndentCharParser ()+keyword = reserved tokP -ident ∷ IndentCharParser st String-ident = identifier haskell+ident ∷ IndentCharParser String+ident = identifier tokP -sym ∷ String → IndentCharParser st String-sym = symbol haskell+sym ∷ String → IndentCharParser String+sym = symbol tokP++equals ∷ IndentCharParser ()+equals = reservedOp tokP "="
examples/WW-beta-saving-0.l view
@@ -1,1 +1,1 @@-(\F. (\f. f (f 0)) (F 0)) (\y. \x. x) +(\F. (\f. f (f 0)) (F 0)) (\y. \x. x)
examples/WW-beta-saving-1.l view
@@ -1,1 +1,1 @@-(\F. (\f. f (f 0)) (F (F 0 0))) (\y. \x. x) +(\F. (\f. f (f 0)) (F (F 0 0))) (\y. \x. x)
− examples/case/sum.l
@@ -1,5 +0,0 @@-let- sum list = case list of- Nil -> 0- Cons z zs -> (\x.λy -> + x y) z (sum zs)-in sum (Cons 1 (Cons 2 Nil))
examples/levy-1988-p184bottom.l view
@@ -1,6 +1,6 @@ let I0 = \x0.x0 I1 = \x1.x1 J = \z.b- Delta = \y.I1 (y y) + Delta = \y.I1 (y y) in (\f.(f I0)(f J)) (\x. Delta (x a))
+ examples/sum_case.l view
@@ -0,0 +1,4 @@+let+ sum list = case list of Nil -> 0+ Cons z zs -> (\x.λy -> plus x y) z (sum zs)+in sum (Cons 1 (Cons 2 Nil))
examples/vincent-1-ww.l view
@@ -1,4 +1,4 @@-let G = \g. g (g x) +let G = \g. g (g x) F x = F x- I x = x + I x = x in G (F I)
graph-rewriting-lambdascope.cabal view
@@ -1,5 +1,5 @@ Name: graph-rewriting-lambdascope-Version: 0.5.10+Version: 0.5.11 Copyright: (c) 2010, Jan Rochel License: BSD3 License-File: LICENSE@@ -8,28 +8,31 @@ Homepage: http://rochel.info/#graph-rewriting Stability: alpha Build-Type: Simple-Synopsis: Lambdascope, an optimal evaluator of the lambda calculus, as an interactive graph-rewriting system-Description: Lambdascope is an optimal evaluator of the λβ-calculus described in the paper "Lambdascope - Another optimal implementation of the lambda-calculus" by Vincent van Oostrom, Kees-Jan van de Looij, and Marijn Zwitserlood. Call "lambdascope" with one of the files from the "examples" directory as an argument. For usage of the GUI see "GraphRewriting.GL.UI". Use the "--lmo" flag for leftmost outermost evalution and "--bench" for non-graphical evaluation to weak head normal form.+Synopsis: Lambdascope, an optimal evaluator of the lambda calculus+Description: Lambdascope is an optimal evaluator of the λβ-calculus described in the paper "Lambdascope - Another optimal implementation of the lambda-calculus" by Vincent van Oostrom, Kees-Jan van de Looij, and Marijn Zwitserlood. This package contains an interactive application, which implements Lambdascope as a port-graph rewriting system. Call "lambdascope" with one of the files from the "examples" directory as an argument. For usage of the GUI see "GraphRewriting.GL.UI". Use the "--lmo" flag for leftmost outermost evalution and "--bench" for non-graphical evaluation to weak head normal form. Category: Compilers/Interpreters, Application-Cabal-Version: >= 1.6-Data-Files: examples/*.l examples/case/*.l+Cabal-Version: >= 1.10+Data-Files: examples/*.l examples/*.l Extra-Source-Files: AUTHORS Executable lambdascope+ Default-Language: Haskell2010 Main-Is: Main.hs Build-Depends:- base >= 4.8 && < 4.10,+ base >= 4.9 && < 5, base-unicode-symbols >= 0.2 && < 0.3,- graph-rewriting >= 0.7.8,- graph-rewriting-layout >= 0.5.4,- graph-rewriting-gl >= 0.7.6,- graph-rewriting-strategies >= 0.2.4,+ graph-rewriting >= 0.7.8 && < 0.9,+ graph-rewriting-layout >= 0.5.4 && < 0.6,+ graph-rewriting-gl >= 0.7.6 && < 0.8,+ graph-rewriting-strategies >= 0.2.4 && < 0.3,+ mtl >= 1.1 && < 2.3, parsec >= 3.1 && < 3.2,- GLUT >= 2.2 && < 2.8,- OpenGL >= 3.0 && < 3.1,- IndentParser >= 0.2 && < 0.3- Extensions:+ GLUT >= 2.2 && < 3,+ OpenGL >= 3.0 && < 4,+ indentparser >= 0.1 && < 0.2+ Default-Extensions: UnicodeSyntax+ Other-Extensions: FlexibleInstances FlexibleContexts MultiParamTypeClasses