Feval (empty) → 1.0.0.0
raw patch · 5 files changed
+298/−0 lines, 5 filesdep +basedep +containersdep +mtlsetup-changed
Dependencies added: base, containers, mtl, parsec
Files
- Feval.cabal +81/−0
- LICENSE +21/−0
- Setup.hs +2/−0
- examples.hs +157/−0
- feval.hs +37/−0
+ Feval.cabal view
@@ -0,0 +1,81 @@+-- Initial Feval.cabal generated by cabal init. For further documentation,+-- see http://haskell.org/cabal/users-guide/++-- The name of the package.+name: Feval++-- The package version. See the Haskell package versioning policy (PVP) +-- for standards guiding when and how versions should be incremented.+-- http://www.haskell.org/haskellwiki/Package_versioning_policy+-- PVP summary: +-+------- breaking API changes+-- | | +----- non-breaking API additions+-- | | | +--- code changes with no API change+version: 1.0.0.0++-- A short (one-line) description of the package.+synopsis: Evaluation using F-Algebras++-- A longer description of the package.+description:+ Feval is a statically typed functional programming language that+ uses f-algebras as opposed to classic recursion to solve the problem+ of evaluation and typechecking, which allows the compiler to perform+ better optimizations.++-- URL for the project homepage or repository.+homepage: http://github.com/burz/Feval++-- The license under which the package is released.+license: MIT++-- The file containing the license text.+license-file: LICENSE++-- The package author(s).+author: Anthony Burzillo++-- An email address to which users can send suggestions, bug reports, and +-- patches.+maintainer: anthonyburz@gmail.com++-- A copyright notice.+-- copyright: ++category: Language++build-type: Simple++-- Constraint on the version of Cabal needed to build this package.+cabal-version: >=1.8++flag buildExamples+ description: Build example executables+ default: False++source-repository head+ type: git+ location: git://github.com/burz/Feval.git++executable Feval+ -- .hs or .lhs file containing the Main module.+ main-is: feval.hs+ + -- Modules included in this executable, other than Main.+ -- other-modules: + + -- Other library packages from which modules are imported.+ build-depends: base ==4.6.*, parsec ==3.1.*, containers ==0.5.*, mtl ==2.1.*+ +executable examples+ -- .hs or .lhs file containing the Main module.+ main-is: examples.hs+ + -- Modules included in this executable, other than Main.+ -- other-modules: + + if flag(buildExamples)+ -- Other library packages from which modules are imported.+ build-depends: base ==4.6.*, parsec ==3.1.*, containers ==0.5.*, mtl ==2.1.*+ else+ buildable: False+
+ LICENSE view
@@ -0,0 +1,21 @@+The MIT License (MIT)++Copyright (c) 2014 Anthony Burzillo++Permission is hereby granted, free of charge, to any person obtaining a copy+of this software and associated documentation files (the "Software"), to deal+in the Software without restriction, including without limitation the rights+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell+copies of the Software, and to permit persons to whom the Software is+furnished to do so, subject to the following conditions:++The above copyright notice and this permission notice shall be included in+all copies or substantial portions of the Software.++THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN+THE SOFTWARE.
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ examples.hs view
@@ -0,0 +1,157 @@+import FVL.FAST+import FVL.Algebra+import qualified FVL.F as F+import qualified FVL.EF as EF++-- (2 + 3) * 4+intExpr = Fx $ (Fx $ (Fx $ CInt 2) `Add` (Fx $ CInt 3)) `Mul` (Fx $ CInt 4)++-- 4 / (3 - 1)+anotherIntExpr = Fx $ (Fx $ CInt 4) `Div` (Fx $ (Fx $ CInt 3) `Sub` (Fx $ CInt 1))++-- (False || True) && True+boolExpr = Fx $ (Fx $ (Fx $ CBool False) `Or` (Fx $ CBool True)) `And` (Fx $ CBool True)++-- !True+notExpr = Fx $ Not (Fx $ CBool True)++-- (2 + 3) = 4+eqlExpr = Fx $ (Fx $ (Fx $ CInt 2) `Add` (Fx $ CInt 3)) `Equal` (Fx $ CInt 4)++-- False || 500+badExpr = Fx $ (Fx $ CBool False) `Or` (Fx $ CInt 500)++-- If True Then 3 Else 4+ifExpr = Fx $ (If (Fx $ CBool True) (Fx $ CInt 3) (Fx $ CInt 4)) ++-- Function x -> True && x+funExpr = Fx $ Function "x" (Fx $ And (Fx $ CBool True) (Fx $ CVar "x"))++-- (Function x -> x + 4) 2+applExpr = Fx $ Appl (Fx $ Function "x" (Fx $ Add (Fx $ CVar "x") (Fx $ CInt 4))) (Fx $ CInt 2)++-- Let Rec f x = If x = 0 Then 0 Else x + f (x - 1) In f 3+letRecExpr = let eql = Fx $ Equal (Fx $ CVar "x") (Fx $ CInt 0) in+ let appl = Fx $ Appl (Fx $ CVar "f") (Fx $ Add (Fx $ CVar "x") (Fx $ CInt (-1))) in+ let els = Fx $ Add (Fx $ CVar "x") appl in+ let ifstmt = Fx $ If eql (Fx $ CInt 0) els+ in Fx $ LetRec "f" "x" ifstmt (Fx $ Appl (Fx $ CVar "f") (Fx $ CInt 3))++-- Let Rec f x = Function y -> If x = 0 Then If y = 0 Then 0 Else y + f x (y - 1) Else x + f (x - 1) y+-- In f 3 3+twoArgRecExpr = let eql s = Fx $ Equal (Fx $ CVar s) (Fx $ CInt 0) in+ let min s = Fx $ Sub (Fx $ CVar s) (Fx $ CInt 1) in+ let tripapp f x y = Fx $ Appl (Fx $ Appl (Fx $ CVar f) x) y in+ let xadd = Fx $ Add (Fx $ CVar "x") (tripapp "f" (min "x") (Fx $ CVar "y")) in+ let yadd = Fx $ Add (Fx $ CVar "y") (tripapp "f" (Fx $ CVar "x") (min "y")) in+ let innerif = Fx $ If (eql "y") (Fx $ CInt 0) yadd in+ let ifstmt = Fx $ If (eql "x") innerif xadd in+ let fun = Fx $ Function "y" ifstmt+ in Fx $ LetRec "f" "x" fun (tripapp "f" (Fx $ CInt 3) (Fx $ CInt 3))++-- Let x = 4 In x + 4+letExpr = Fx $ EF.Let "x" [] (Fx $ EF.CInt 4) (Fx $ EF.Add (Fx $ EF.CVar "x") (Fx $ EF.CInt 4))++-- 4; True+semiExpr = Fx $ EF.Semi (Fx $ EF.CInt 4) (Fx $ EF.CBool True)++-- Let f x y = x - y In f 4 5+eefLetExpr = let add = Fx $ EF.Sub (Fx $ EF.CVar "x") (Fx $ EF.CVar "y") in+ let innerappl = Fx $ EF.Appl (Fx $ EF.CVar "f") (Fx $ EF.CInt 4) in+ let appl = Fx $ EF.Appl innerappl (Fx $ EF.CInt 5)+ in Fx $ EF.Let "f" ["x", "y"] add appl++-- Let f x y = If x = 0 Then If y = 0 Then 0 Else y + f x (y - 1) Else x + f (x - 1) y In f 3 3+recExpr = let eql s = Fx $ EF.Equal (Fx $ EF.CVar s) (Fx $ EF.CInt 0) in+ let min s = Fx $ EF.Sub (Fx $ EF.CVar s) (Fx $ EF.CInt 1) in+ let tripapp f x y = Fx $ EF.Appl (Fx $ EF.Appl (Fx $ EF.CVar f) x) y in+ let xadd = Fx $ EF.Add (Fx $ EF.CVar "x") (tripapp "f" (min "x") (Fx $ EF.CVar "y")) in+ let yadd = Fx $ EF.Add (Fx $ EF.CVar "y") (tripapp "f" (Fx $ EF.CVar "x") (min "y")) in+ let innerif = Fx $ EF.If (eql "y") (Fx $ EF.CInt 0) yadd in+ let ifstmt = Fx $ EF.If (eql "x") innerif xadd+ in Fx $ EF.Let "f" ["x", "y"] ifstmt (tripapp "f" (Fx $ EF.CInt 3) (Fx $ EF.CInt 3))++intS = "1"++boolS = "True"++varS = "hello"++addS = "4 + 6 + 45"++subS = "784 - 84"++mulS = "5 * 5"++divS = "56 / 32"++andS = "True && False"++orS = "True || False"++notS = "!False"++equalS = "67 = 45"++ifS = "If 5 = 5 Then 5 Else 6"++functionS = "Function x -> x + 56"++applS = "(Function x -> True && x) False"++letS = "Let f x = If x = 0 Then 0 Else x + (f (x - 1)) In f 3"++semiS = "True; 75"++crazyLetS = "Let f x y z = Function w -> If w = 0 Then 0 Else f w x y z In f 1 1 1 0"++intListS = "[0, 1, 2, 5]"++boolListS = "[True, False, False]"++listCaseS = "Case [1, 2, 3, 4, 5] Of [] -> [3, 4] | (x:xs) -> x : xs"++listFunS = "(Function x -> Case x Of [] -> True | (x:xs) -> x && True) [True, False, True]"++main = do+ putStrLn "strict expressions::\n--------------------"+ mapM_ print [ F.run intExpr+ , F.run anotherIntExpr+ , F.run boolExpr+ , F.run notExpr+ , F.run eqlExpr+ , F.run badExpr+ , F.run ifExpr+ , F.run funExpr+ , F.run applExpr+ , F.run letRecExpr+ , F.run twoArgRecExpr+ , EF.run letExpr+ , EF.run semiExpr+ , EF.run recExpr+ , EF.run eefLetExpr+ ]+ putStrLn "parsed expressions::\n--------------------"+ mapM_ print [ EF.parseRun intS+ , EF.parseRun boolS+ , EF.parseRun varS+ , EF.parseRun addS+ , EF.parseRun subS+ , EF.parseRun mulS+ , EF.parseRun divS+ , EF.parseRun andS+ , EF.parseRun orS+ , EF.parseRun notS+ , EF.parseRun equalS+ , EF.parseRun ifS+ , EF.parseRun functionS+ , EF.parseRun applS+ , EF.parseRun letS+ , EF.parseRun semiS+ , EF.parseRun crazyLetS+ , EF.parseRun intListS+ , EF.parseRun boolListS+ , EF.parseRun listCaseS+ , EF.parseRun listFunS+ ]+
+ feval.hs view
@@ -0,0 +1,37 @@+import System.Environment+import Control.Applicative+import Control.Monad++import FVL.Parser+import FVL.EF++parseTranslateShow :: String -> Either ParseError String+parseTranslateShow s = case parseString s of+ Left e -> Left e+ Right e -> Right $ showTranslation e++showResult :: Either ParseError Result -> String+showResult (Right (Result (e, t))) = " => " ++ show e ++ "\n : " ++ show t+showResult (Right TypeMismatch) = "Error: Type Mismatch"+showResult (Right InconsistentTypes) = "Error: Inconsistent Types"+showResult (Left e) = "Error: " ++ show e++getLines :: IO ()+getLines = do+ l <- getLine+ if l == "\EOT" then return () else do+ putStrLn . showResult $ parseRun l+ getLines+ return ()++getFileLines :: FilePath -> IO ()+getFileLines p = do+ r <- parseFileRun p+ putStrLn $ showResult r++main = do+ a <- getArgs+ case a of+ [] -> getLines+ (p:_) -> getFileLines p+