source: sizechecking/NC.hs @ 5

Last change on this file since 5 was 5, checked in by gobi, 13 years ago

size checking

File size: 1013 bytes
Line 
1
2{- Constraints -}
3newtype Term = Term [String]
4    deriving (Show, Eq, Ord)
5nullterm = Term []
6newtype Arithmetics = Arithmetics (Map Term Int)
7    deriving (Show, Eq)
8
9termmul (Term a) (Term b) = Term $ termmul' a b
10    where
11    termmul' []        l         = l
12    termmul' l         []        = l
13    termmul' l1@(x:xs) l2@(y:ys) = if x<y then x:termmul' xs l2
14                                          else y:termmul' l1 ys
15
16instance Num Arithmetics where
17    fromInteger l = Arithmetics $ singleton nullterm $ fromInteger l
18    (Arithmetics a) + (Arithmetics b) = Arithmetics $ unionWith (+) a b
19    (Arithmetics a) * (Arithmetics b) = Arithmetics amul
20        where
21        amul = foldrWithKey tmul empty a
22        tmul :: Term -> Int -> Map Term Int -> Map Term Int
23        tmul t1 v1 val = unionWith (+) val (mapKeys (termmul t1) $ M.map (*v1) b)
24    abs = undefined
25    signum = undefined
26
27data Condition = ZC Arithmetics | LTC Arithmetics Arithmetics | GEC Arithmetics Arithmetics
28    deriving (Show)
Note: See TracBrowser for help on using the repository browser.