3 ms·
You can come up w/ an algebra for a specific problem domain by thinking about the data models and repurposing some simple abstract algebra. E.g.: new(stat
by hcarvalhoalves 7y ago
You can come up w/ an algebra for a specific problem domain by thinking about the data models and repurposing some simple abstract algebra.
E.g.:
new(state, &args) => mutation
apply(state, mutation) => state'
Applied to finance:
newPayment(balanceSheet, amount, date) => payment
apply(balanceSheet, payment) => balanceSheet'
newDiscount(balanceSheet', amount, date) => discount
apply(balanceSheet', discount) => balanceSheet''
Applied to chess:
newMovement(board, K, E2) => movement
apply(board, movement) => board'
newMovement(board', b, D6) => movement'
apply(board', movement') => board''
As a bonus, it's clear where to enforce invariants and fail early:
newMovement(board', K, E3) => Illegal Movement (Can't move to E3)
newMovement(board'', K, E2) => Illegal Movement (White King not available on board)
apply(board''', randomMovement) => Illegal Play
- ignoramous 7y agoYou'd like: https://blog.ploeh.dk/2017/10/04/from-design-patterns-to-category-theory/ https://blog.ploeh.dk/2017/10/04/from-design-patterns-to-cat...