JavaCompilerCore/resources/bytecode/javFiles/PatternMatchingHaskellStyle.jav
Daniel Holle e2bf09548f
Some checks failed
Build and Test with Maven / Build-and-test-with-Maven (push) Failing after 50s
Rename test file and some work on the overloading behavior
2024-11-07 17:04:43 +01:00

21 lines
586 B
Java

import java.lang.Boolean;
sealed interface List<T> permits LinkedElem, Elem {}
public record LinkedElem<T>(T a, List<T> l) implements List<T> {}
public record Elem<T>(T a) implements List<T> {}
public class PatternMatchingHaskellStyle {
public append(LinkedElem(a, b), list2) {
return handleAppend(a, b, list2);
}
private handleAppend(a, Elem(e), list2) {
return new LinkedElem<>(a, new LinkedElem<>(e, list2));
}
private handleAppend(a, LinkedElem(e,r), list2) {
return new LinkedElem<>(a, append(new LinkedElem(e, r), list2));
}
}