Changeset 12 for sizechecking/SizedExp.hs
- Timestamp:
- Nov 15, 2012, 12:44:36 AM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sizechecking/SizedExp.hs
r11 r12 11 11 import Constraints 12 12 import Data.Supply 13 13 import Control.Arrow 14 import Control.Monad 14 15 15 16 class TS b => (Unify se a b) where … … 19 20 20 21 instance (SizedExp se, Unify se a b, se~se1, c1~c2, TS c2) => Unify se (Size se1 c1->a) (c2->b) where 21 unify f g x = f undefined x22 unify f g = f undefined 22 23 23 24 instance (SizedExp se, se~se1, c1~c2, TS c2) => Unify se (Size se1 c1) c2 where 24 unify f g x = g undefined x25 unify f g = g undefined 25 26 26 27 class SizedExp (se :: * -> *) where … … 77 78 (s1, s2, s3) = split3 supply 78 79 freshvars' :: (Unify Q a b) => (a -> (Size Q b, L -> L)) -> (Size Q c -> a) -> (Size Q (c -> b), L -> L) 79 freshvars' u exp = (QSynt $ sizeof $x, \l -> f $ App l fv)80 freshvars' u exp = (QSynt $ sizeof x, \l -> f $ App l fv) 80 81 where 81 82 (x, f) = u $ exp $ QSynt $ do 82 putStrLn $ "[Bind] var="++ (show fv)++" of type "++(show $tk q)83 putStrLn $ "[Bind] var="++ show fv ++" of type "++ show (tk q) 83 84 return [([], fv)] 84 85 fv = fresh (tk q) s3 85 86 86 87 addConstraint :: Constraint -> [SExp] -> [SExp] 87 addConstraint nc = map ( \(c,l) -> (nc:c, l))88 addConstraint nc = map (first ((:) nc)) 88 89 89 90 concatMapM :: (a -> IO [b]) -> [a] -> IO [b] 90 concatMapM f l = mapM f l >>= return.concat91 concatMapM f l = liftM concat $ mapM f l 91 92 92 93 type SExp = ([Constraint], L) … … 99 100 match1 (cond, ltype) = do 100 101 x <- sizeof l 101 putStrLn $ "ORIGINAL is " ++ (show x)102 putStrLn $ "[MATCH] ==> " ++ (show $ ltype)102 putStrLn $ "ORIGINAL is " ++ show x 103 putStrLn $ "[MATCH] ==> " ++ show ltype 103 104 let lt = rall$ App (AAbs 18 5 $ Var 18) ltype 104 putStrLn $ " --- NIL ---" ++ (show lt)105 putStrLn $ " --- NIL ---" ++ show lt 105 106 nils <- sizeof nil 106 p utStrLn $ shownils107 print nils 107 108 let nilc = foldr addConstraint nils $ Zero lt:cond 108 109 let tx = rall $ App (AAbs 18 5 $ App (Var 5) (Op (Var 18) '-' (Num 1))) ltype 109 110 let txs = rall $App (AAbs 18 5 $ List (Op (Var 18) '-' (Num 1)) (Var 5)) ltype 110 putStrLn $ " --- CONS --- "++ (show tx)++" <-> "++(show txs)111 putStrLn $ " --- CONS --- "++ show tx ++" <-> "++ show txs 111 112 conss <- sizeof $ cons (QSynt$return [([], tx)]) (QSynt$return [([], txs)]) 112 113 print conss … … 151 152 fromInteger = num 152 153 153 prove :: Size Q b -> IO (Bool)154 prove :: Size Q b -> IO Bool 154 155 prove (QProvable l x) = do 155 (s1,s2,s3) <- newSupply 30 (+1) >>= return.split3156 (s1,s2,s3) <- liftM split3 $ newSupply 30 (+1) 156 157 c <- x s1 157 158 putStrLn ""
Note: See TracChangeset
for help on using the changeset viewer.