// simulating conditionals in FJ // (call-by-name conditionals) // true = \x.\y.x // false = \x.\y.y // if L then M else N == L M N // (simulating call-by-name with call-by-value) // delay M = \().M // force L = L () // (call-by-value conditionals) // true == \x.\y.force y // false == \x.\y.force x // if L then M else N == L (delay M) (delay N) class Runnable extends Object { Runnable() { super(); } Object run() { return new Object(); } } class Bool extends Object { Bool() { super(); } Object cond(Runnable ifTrue, Runnable ifFalse) { return new Object(); } } class True extends Bool { True() { super(); } Object cond(Runnable ifTrue, Runnable ifFalse) { return ifTrue.run(); } } class False extends Bool { False() { super(); } Object cond(Runnable ifTrue, Runnable ifFalse) { return ifFalse.run(); } } class Runnable1 extends Runnable { Runnable1() { super(); } Object run() { return new Integer(1+2); } } class Runnable2 extends Runnable { Runnable2() { super(); } Object run() { return new Integer(3/0); } } class Feath2 extends Object { public static void main(String[] args) { System.out.println(new True().cond(new Runnable1(), new Runnable2())); System.out.println(new False().cond(new Runnable1(), new Runnable2())); } }