Encoding algebraic data types in Java using fold