# Translation From Act -> OG ## Act Spec ```act constructor of Token interface constructor (address a, uint256 amt) creates mapping(address => uint256) balances := [a := amt] ``` ```act behaviour transfer of Token interface transfer(address to, uint256 amt) iff in range uint256 balances[to] + amt balances[CALLER] - amt case CALLER =/= to: storage balances[CALLER] => balances[CALLER] - amt balances[to] => balances[to] + amt case CALLER == to: balances[CALLER] balances[to] ``` ## Potential Haskell Code ```haskell -- generated from the Store datatype in the act AST data State = State { balances :: Map Address Integer } -- generated from the EthEnv datatype in the act AST data Ctx = Ctx { caller :: Address } -- generated from all of the Interfaces for a given contract in the act AST data Tx = Transfer Address Integer constructor :: Address -> Integer -> State constructor addr val = State { balances = Map.insert addr val mempty } exec :: Ctx -> State -> Tx -> State -- we could alternatively call out to some act evaluator here instead of compiling each behaviour into haskell directly exec ctx state (Transfer addr amt) = transfer ctx state addr amt transfer :: Ctx -> State -> Address -> Integer -> State transfer ctx pre to amt = if preconds then if caller ctx == to then pre else State {balances = addBal} else pre where preTo = Map.lookup (balances pre) to preCaller = Map.lookup (balances pre) (caller ctx) preconds = 0 <= preTo + amt && preTo + amt <= (maxBound :: Word256) && 0 <= preCaller - amt && preCaller - amt <= (maxBound :: Word256) subBal = Map.insert (caller ctx) ((Map.lookup (caller ctx) (balances state)) - amt) (balances state) addBal = Map.insert to (Map.lookup to subBal + amt) subBal ```