JavaCompilerCore/resources/bytecode/javFiles/PaternMatchingHaskellStyle.jav
Ruben 4d1950d0ba
Some checks failed
Build and Test with Maven / Build-and-test-with-Maven (push) Failing after 42s
feat: add Example for HaskellStyle Pattern Matching
2024-10-25 12:06:23 +02:00

15 lines
421 B
Java

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 PaternMatchingHaskellStyle {
public append(LinkedElem(a, Elem(e)), l2) {
return new LinkedElem<>(a, new LinkedElem<>(e, l2));
}
public append(LinkedElem(a, r), l2) {
return new LinkedElem<>(a, append(r, l2));
}
}