strategyPeanoPlus.tex 724 B

12345678910111213141516171819
  1. \begin{tomcode3}[label=code:strategyPeanoTransform,caption=Exemple d'utilisation de stratégie.]
  2. %strategy transformationPeano() extends Identity() {
  3. visit Nat {
  4. plus(x, zero()) -> { return `x; }
  5. plus(zero(), x) -> { return `x; }
  6. one() -> { return `suc(zero()); }
  7. }
  8. }
  9. ...
  10. public static void main(String[] args) {
  11. ...
  12. Nat number = `plus(plus(suc(suc(one())), one()),
  13. plus(suc(one()), zero()) );
  14. Strategy transformStrat = `BottomUp(transformationPeano());
  15. Nat transformedNumber = transformStrat.visit(number);
  16. System.out.println(number + " a #\texttt{é}#t#\texttt{é}# transform#\texttt{é}# en " + transformedNumber);
  17. ...
  18. }
  19. \end{tomcode3}