Changeset 24 for sizechecking
- Timestamp:
- May 3, 2014, 6:38:40 PM (11 years ago)
- Location:
- sizechecking/branches/macs
- Files:
-
- 1 deleted
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
sizechecking/branches/macs/Exp.hs
r23 r24 38 38 showString "; (" . showVar v1 . showChar ':' . showVar v2 . showString ") => " . 39 39 unS (cbranch showV1 showV2) s3 0 40 cond c tbranch fbranch = S $ \s p -> 41 let (s1, s2, s3) = S.split3 s 42 in showParen (p>0) $ 43 showString "if ". 44 unS c s1 0 . 45 showString " then " . 46 unS tbranch s2 0 . 47 showString " else " . 48 unS fbranch s3 0 -
sizechecking/branches/macs/Lambda.hs
r23 r24 11 11 lam :: (l a -> l b) -> l (a -> b) 12 12 app :: l (a -> b) -> l a -> l b 13 const :: Int -> l Int13 lit :: Int -> l Int 14 14 15 15 {- … … 18 18 newtype Q a = Q { unQ :: a } 19 19 instance Lambda Q where 20 const = Q20 lit = Q 21 21 lam a = Q (unQ.a.Q) 22 22 app a b = Q $ unQ a (unQ b) … … 37 37 38 38 instance Lambda S where 39 const a = S (\_ p -> showsPrec p a)39 lit a = S (\_ p -> showsPrec p a) 40 40 app (S fun) (S arg) = S (\s p -> 41 41 let (s1, s2) = S.split2 s -
sizechecking/branches/macs/tests/ExpTest.hs
r23 r24 5 5 import Lambda 6 6 import Exp 7 import Prelude ( ($), Int, (==), return, sequence, (>>=), and, (.), IO, Bool )7 import Prelude ( ($), Int, (==), return, sequence, (>>=), and, (.), IO, Bool, String, const ) 8 8 import qualified Control.Monad 9 9 … … 12 12 13 13 testAddOne :: Exp e => e ([Int] -> [Int]) 14 testAddOne = lam $ \l -> cons ( const 1) l14 testAddOne = lam $ \l -> cons (lit 1) l 15 15 16 16 testHead :: Exp e => e ([a] -> a) 17 testHead = lam $ \l -> match l undefined $ \x _ -> x17 testHead = lam $ \l -> match l undefined const 18 18 19 19 testTail :: Exp e => e ([a] -> [a]) … … 24 24 $ \x xs -> cons x (testConcat `app` xs `app` l2) 25 25 26 test EvalNil :: IO Bool27 test EvalNil = return $ ([]::[Int]) == eval testNil26 testDCons :: Exp e => e [Int] 27 testDCons = cons (lit 1) $ cons (lit 2) nil 28 28 29 test EvalAddOne :: IO Bool30 test EvalAddOne = return $ [1::Int] == (eval $ testAddOne `app` nil)29 testD2Cons :: Exp e => e [[Int]] 30 testD2Cons = cons (cons (lit 1) nil) nil 31 31 32 testEvalTail ::IO Bool33 testEvalTail = return $ [2..6::Int] == eval testTail [1..6] 32 checkAST :: S a -> String -> IO Bool 33 checkAST exp repr = ast exp >>= (\t -> return $ t "" == repr ) 34 34 35 testEvalConcat :: IO Bool 36 testEvalConcat = return $ [1..6::Int] == eval testConcat [1,2,3] [4,5,6] 35 tests :: [ IO Bool ] 36 tests = 37 [ return $ ([]::[Int]) == eval testNil 38 , checkAST testNil "[]" 39 , return $ [1::Int] == eval (testAddOne `app` nil) 40 , checkAST testAddOne "λa.1:a" 41 , return $ [2..6::Int] == eval testTail [1..6] 42 , return $ [1..6::Int] == eval testConcat [1,2,3] [4,5,6] 43 , return $ [1,2::Int] == eval testDCons 44 , checkAST testDCons "1:2:[]" 45 , return $ [[1::Int]] == eval testD2Cons 46 , checkAST testD2Cons "(1:[]):[]" 47 ] 37 48 38 tests :: [IO Bool]39 40 tests = [ testEvalNil41 , testEvalAddOne42 , testEvalTail43 , testEvalConcat44 ]45 49 46 50 runTests :: IO Bool -
sizechecking/branches/macs/tests/LambdaTest.hs
r21 r24 8 8 9 9 test1 :: (Lambda l) => l Int 10 test1 = app (lam $ \_ -> const 3) (const 2)10 test1 = app (lam $ \_ -> lit 3) (lit 2) 11 11 12 12 test1ast :: IO Bool -
sizechecking/branches/macs/tests/Main.hs
r21 r24 3 3 import qualified Tests.LambdaTest (tests) 4 4 import qualified Tests.OpsTest (tests) 5 import qualified Tests.SizeTest (tests) 6 import qualified Tests.ExpTest (tests) 5 7 import Control.Monad 6 8 … … 8 10 tests = Tests.LambdaTest.tests 9 11 ++ Tests.OpsTest.tests 12 ++ Tests.SizeTest.tests 13 ++ Tests.ExpTest.tests 10 14 11 15 main :: IO () -
sizechecking/branches/macs/tests/OpsTest.hs
r22 r24 9 9 10 10 test1 :: (LOps l) => l Int 11 test1 = app (lam $ \x -> const 3 + x) (const 2)11 test1 = app (lam $ \x -> lit 3 + x) (lit 2) 12 12 13 13 test2 :: (LOps l) => l Int 14 test2 = app (lam $ \x -> const 3 * x) (const 2)14 test2 = app (lam $ \x -> lit 3 * x) (lit 2) 15 15 16 16 test3 :: (LOps l) => l Int 17 test3 = app (lam $ \x -> const 2 * x + const 1) (const 5 - const 2)17 test3 = app (lam $ \x -> lit 2 * x + lit 1) (lit 5 - lit 2) 18 18 19 19 -
sizechecking/branches/macs/tests/SizeTest.hs
r22 r24 6 6 import Lambda 7 7 import Ops 8 import Prelude ( ($), Int, (==), return, sequence, (>>=), and, (.), IO, Bool ) 8 import Prelude ( ($), Int, (==), return, sequence, (>>=), and, (.), IO, Bool, String, const ) 9 import qualified Control.Monad 9 10 10 11 testEmpty1 :: (Size l) => l [Unsized] 11 testEmpty1 = list ( const 0) (lam $ \_ ->unsized)12 testEmpty1 = list (lit 0) (lam $ const unsized) 12 13 13 14 testNil :: (Size l) => l [a] 14 testNil = list ( const 0) (lam $ \_ ->bottom)15 testNil = list (lit 0) (lam $ const bottom) 15 16 16 17 testHead :: (Size l) => l ([a] -> a) 17 testHead = slam $ \s f -> f `app` (s - const 1)18 testHead = slam $ \s f -> f `app` (s - lit 1) 18 19 19 20 testTail :: (Size l) => l ([a] -> [a]) 20 testTail = slam $ \s f -> list (s - const 1) f21 testTail = slam $ \s f -> list (s - lit 1) f 21 22 22 23 testCons :: Size l => l (a -> [a] -> [a]) 23 24 testCons = lam $ \x -> slam $ \s f -> 24 list (s + const 1) $ shift f s (lam $ \_ -> x) 25 list (s + lit 1) $ shift f s (lam $ const x) 26 27 checkAst :: S a -> String -> IO Bool 28 checkAst exp repr = ast exp >>= (\t -> return $ t "" == repr) 29 30 tests :: [IO Bool] 31 tests = [ 32 checkAst testEmpty1 "List 0 (λa.U)" 33 , checkAst testNil "List 0 (λa.âŽ)" 34 , checkAst testHead "Îa,b.b (a-1)" 35 , checkAst testTail "Îa,b.List (a-1) b" 36 , checkAst testCons "λa.Îb,c.List (b+1) (Shift c b (λd.a))" 37 ] 38 39 runTests :: IO Bool 40 runTests = Control.Monad.liftM and $ sequence tests
Note: See TracChangeset
for help on using the changeset viewer.