Changeset 24 for sizechecking


Ignore:
Timestamp:
May 3, 2014, 6:38:40 PM (11 years ago)
Author:
gobi
Message:

expressions

Location:
sizechecking/branches/macs
Files:
1 deleted
7 edited

Legend:

Unmodified
Added
Removed
  • sizechecking/branches/macs/Exp.hs

    r23 r24  
    3838            showString "; (" .  showVar v1 . showChar ':' . showVar v2 . showString ") => " . 
    3939            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  
    1111    lam   :: (l a -> l b) -> l (a -> b) 
    1212    app   :: l (a -> b) -> l a -> l b 
    13     const :: Int -> l Int 
     13    lit :: Int -> l Int 
    1414 
    1515{- 
     
    1818newtype Q a = Q { unQ :: a } 
    1919instance Lambda Q where 
    20     const = Q 
     20    lit = Q 
    2121    lam a = Q (unQ.a.Q) 
    2222    app a b = Q $ unQ a (unQ b) 
     
    3737 
    3838instance Lambda S where 
    39     const a = S (\_ p -> showsPrec p a) 
     39    lit a = S (\_ p -> showsPrec p a) 
    4040    app (S fun) (S arg) = S (\s p ->  
    4141        let (s1, s2) = S.split2 s  
  • sizechecking/branches/macs/tests/ExpTest.hs

    r23 r24  
    55import Lambda 
    66import Exp 
    7 import Prelude ( ($), Int, (==), return, sequence, (>>=), and, (.), IO, Bool ) 
     7import Prelude ( ($), Int, (==), return, sequence, (>>=), and, (.), IO, Bool, String, const ) 
    88import qualified Control.Monad 
    99 
     
    1212 
    1313testAddOne :: Exp e => e ([Int] -> [Int]) 
    14 testAddOne = lam $ \l -> cons (const 1) l 
     14testAddOne = lam $ \l -> cons (lit 1) l 
    1515 
    1616testHead :: Exp e => e ([a] -> a) 
    17 testHead = lam $ \l -> match l undefined $ \x _ -> x 
     17testHead = lam $ \l -> match l undefined const 
    1818 
    1919testTail :: Exp e => e ([a] -> [a]) 
     
    2424    $ \x xs -> cons x (testConcat `app` xs `app` l2) 
    2525 
    26 testEvalNil :: IO Bool 
    27 testEvalNil = return $ ([]::[Int]) == eval testNil 
     26testDCons :: Exp e => e [Int] 
     27testDCons = cons (lit 1) $ cons (lit 2) nil 
    2828 
    29 testEvalAddOne :: IO Bool 
    30 testEvalAddOne = return $ [1::Int] == (eval $ testAddOne `app` nil) 
     29testD2Cons :: Exp e => e [[Int]] 
     30testD2Cons = cons (cons (lit 1) nil) nil 
    3131 
    32 testEvalTail :: IO Bool 
    33 testEvalTail = return $ [2..6::Int] == eval testTail [1..6] 
     32checkAST :: S a -> String -> IO Bool 
     33checkAST exp repr = ast exp >>= (\t -> return $ t "" == repr ) 
    3434 
    35 testEvalConcat :: IO Bool 
    36 testEvalConcat = return $ [1..6::Int] == eval testConcat [1,2,3] [4,5,6]  
     35tests :: [ IO Bool ] 
     36tests =  
     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    ] 
    3748 
    38 tests :: [IO Bool] 
    39  
    40 tests = [ testEvalNil 
    41         , testEvalAddOne 
    42         , testEvalTail 
    43         , testEvalConcat 
    44         ] 
    4549 
    4650runTests :: IO Bool 
  • sizechecking/branches/macs/tests/LambdaTest.hs

    r21 r24  
    88 
    99test1 :: (Lambda l) => l Int 
    10 test1 = app (lam $ \_ -> const 3) (const 2) 
     10test1 = app (lam $ \_ -> lit 3) (lit 2) 
    1111 
    1212test1ast :: IO Bool 
  • sizechecking/branches/macs/tests/Main.hs

    r21 r24  
    33import qualified Tests.LambdaTest (tests) 
    44import qualified Tests.OpsTest (tests) 
     5import qualified Tests.SizeTest (tests) 
     6import qualified Tests.ExpTest (tests) 
    57import Control.Monad 
    68 
     
    810tests = Tests.LambdaTest.tests  
    911     ++ Tests.OpsTest.tests 
     12     ++ Tests.SizeTest.tests 
     13     ++ Tests.ExpTest.tests 
    1014 
    1115main :: IO () 
  • sizechecking/branches/macs/tests/OpsTest.hs

    r22 r24  
    99 
    1010test1 :: (LOps l) => l Int 
    11 test1 = app (lam $ \x -> const 3 + x) (const 2) 
     11test1 = app (lam $ \x -> lit 3 + x) (lit 2) 
    1212 
    1313test2 :: (LOps l) => l Int 
    14 test2 = app (lam $ \x -> const 3 * x) (const 2) 
     14test2 = app (lam $ \x -> lit 3 * x) (lit 2) 
    1515 
    1616test3 :: (LOps l) => l Int 
    17 test3 = app (lam $ \x -> const 2 * x + const 1) (const 5 - const 2) 
     17test3 = app (lam $ \x -> lit 2 * x + lit 1) (lit 5 - lit 2) 
    1818 
    1919 
  • sizechecking/branches/macs/tests/SizeTest.hs

    r22 r24  
    66import Lambda 
    77import Ops 
    8 import Prelude ( ($), Int, (==), return, sequence, (>>=), and, (.), IO, Bool ) 
     8import Prelude ( ($), Int, (==), return, sequence, (>>=), and, (.), IO, Bool, String, const ) 
     9import qualified Control.Monad 
    910 
    1011testEmpty1 :: (Size l) => l [Unsized] 
    11 testEmpty1 = list (const 0) (lam $ \_ -> unsized) 
     12testEmpty1 = list (lit 0) (lam $ const unsized) 
    1213 
    1314testNil :: (Size l) => l [a] 
    14 testNil = list (const 0) (lam $ \_ -> bottom) 
     15testNil = list (lit 0) (lam $ const bottom) 
    1516 
    1617testHead :: (Size l) => l ([a] -> a) 
    17 testHead = slam $ \s f -> f `app` (s - const 1) 
     18testHead = slam $ \s f -> f `app` (s - lit 1) 
    1819 
    1920testTail :: (Size l) => l ([a] -> [a]) 
    20 testTail = slam $ \s f -> list (s - const 1) f 
     21testTail = slam $ \s f -> list (s - lit 1) f 
    2122 
    2223testCons :: Size l => l (a -> [a] -> [a]) 
    2324testCons = 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 
     27checkAst :: S a -> String -> IO Bool 
     28checkAst exp repr = ast exp >>= (\t -> return $ t "" == repr) 
     29 
     30tests :: [IO Bool] 
     31tests = [ 
     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 
     39runTests :: IO Bool 
     40runTests = Control.Monad.liftM and $ sequence tests 
Note: See TracChangeset for help on using the changeset viewer.