-
-
Save ciju/1d7de27cec83eb4b1a8276276b19991b to your computer and use it in GitHub Desktop.
Taxes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//assumes no tax overrides | |
//assumes no tax can replace another tax | |
sig Location {} //states, cities | |
sig Category {} | |
sig Item { | |
, category: some Category | |
} | |
enum TaxRate {Percent, Flat} | |
sig Tax { //should probably have a general rules interface | |
, cost: TaxRate | |
, rules: some Rule | |
} //set means that a tax would ALWAYS apply if no rules | |
abstract sig Rule {} | |
sig LocationRule extends Rule { | |
rule: Location | |
} | |
sig CategoryRule extends Rule { | |
rule: some Category | |
} // can apply if Category A OR B | |
sig CountRule extends Rule { | |
rule: Int | |
} {rule > 0} | |
fact "One locationrule per location" { | |
LocationRule.rule = Location | |
#LocationRule = #Location | |
} | |
fact "Tax type restrictions" { | |
//no so far?! | |
} | |
pred tax_applies[t: Tax, i: Item] { | |
all r: t.rules | | |
r.rule_applies[i] | |
} | |
pred rule_applies[r: Rule, i: Item] { | |
r in LocationRule => r.rule_location[i] else | |
r in CategoryRule => r.rule_category[i] else | |
r in CountRule => r.rule_count[i] | |
} | |
pred rule_location[r: LocationRule, i: Item] { | |
r.rule in Cart.address | |
} | |
pred rule_category[r: CategoryRule, i: Item] { | |
i.category in r.rule | |
} | |
pred rule_count[r: CountRule, i: Item] { | |
Cart.contents[i] <= r.rule | |
} | |
one sig Cart { | |
, contents: set (Item -> lone Int) //gotta have to pay | |
//question: Int -> Item or Item -> Int??? | |
, address: some Location // city in state etc | |
} { | |
no i: Item.contents | i <= 0 | |
} | |
run {some t: Tax, i: Item | #t.rules > 1 and t.tax_applies[i]} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment