Ignore:
Timestamp:
Nov 15, 2012, 12:44:36 AM (13 years ago)
Author:
gobi
Message:

code cleanup

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sizechecking/SizedExp.hs

    r11 r12  
    1111import Constraints  
    1212import Data.Supply 
    13  
     13import Control.Arrow 
     14import Control.Monad 
    1415 
    1516class TS b => (Unify se a b)  where 
     
    1920 
    2021instance (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 x 
     22    unify f g = f undefined 
    2223 
    2324instance (SizedExp se, se~se1, c1~c2, TS c2) => Unify se (Size se1 c1) c2 where 
    24     unify f g x = g undefined x 
     25    unify f g = g undefined 
    2526 
    2627class SizedExp (se :: * -> *) where 
     
    7778    (s1, s2, s3) = split3 supply 
    7879    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) 
    8081        where 
    8182        (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) 
    8384            return [([], fv)] 
    8485        fv = fresh (tk q) s3 
    8586 
    8687addConstraint :: Constraint -> [SExp] -> [SExp] 
    87 addConstraint nc = map (\(c,l) -> (nc:c, l)) 
     88addConstraint nc = map (first ((:) nc)) 
    8889 
    8990concatMapM :: (a -> IO [b]) -> [a] -> IO [b] 
    90 concatMapM f l = mapM f l >>= return.concat 
     91concatMapM f l = liftM concat $ mapM f l 
    9192     
    9293type SExp = ([Constraint], L) 
     
    99100            match1 (cond, ltype) = do 
    100101                    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 
    103104                    let lt = rall$  App (AAbs 18 5 $ Var 18) ltype 
    104                     putStrLn $ " --- NIL  ---" ++ (show lt) 
     105                    putStrLn $ " --- NIL  ---" ++ show lt 
    105106                    nils <- sizeof nil 
    106                     putStrLn $ show nils 
     107                    print nils 
    107108                    let nilc = foldr addConstraint nils $ Zero lt:cond 
    108109                    let tx = rall $ App (AAbs 18 5 $ App (Var 5) (Op (Var 18) '-' (Num 1))) ltype 
    109110                    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 
    111112                    conss <- sizeof $ cons (QSynt$return [([], tx)]) (QSynt$return [([], txs)]) 
    112113                    print conss 
     
    151152    fromInteger = num 
    152153 
    153 prove :: Size Q b -> IO (Bool) 
     154prove :: Size Q b -> IO Bool 
    154155prove (QProvable l x) = do 
    155     (s1,s2,s3) <- newSupply 30 (+1) >>= return.split3 
     156    (s1,s2,s3) <- liftM split3 $ newSupply 30 (+1) 
    156157    c <- x s1 
    157158    putStrLn "" 
Note: See TracChangeset for help on using the changeset viewer.