Rev | Line | |
---|
[5] | 1 | |
---|
| 2 | {- Constraints -} |
---|
| 3 | newtype Term = Term [String] |
---|
| 4 | deriving (Show, Eq, Ord) |
---|
| 5 | nullterm = Term [] |
---|
| 6 | newtype Arithmetics = Arithmetics (Map Term Int) |
---|
| 7 | deriving (Show, Eq) |
---|
| 8 | |
---|
| 9 | termmul (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 | |
---|
| 16 | instance 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 | |
---|
| 27 | data Condition = ZC Arithmetics | LTC Arithmetics Arithmetics | GEC Arithmetics Arithmetics |
---|
| 28 | deriving (Show) |
---|
Note: See
TracBrowser
for help on using the repository browser.