Files
JavaCompilerCore/resources/bytecode/javFiles/PatternMatching.jav
Daniel Holle 9117a608c8
Some checks failed
SonarQube Scan / SonarQube Trigger (push) Failing after 1m16s
Fix up some stuff
2026-01-15 18:16:49 +01:00

25 lines
830 B
Java

sealed interface List<T> permits Cons, Empty {}
public record Cons<T>(T a, List<T> l) implements List<T> {}
public record Empty<T>() implements List<T> {}
public record Tuple<T1, T2>(T1 a, T2 b) {}
public class PatternMatching {
public zip(Cons(x, xs), Cons(y, ys)) {
return new Cons(new Tuple(x, y), zip(xs, ys));
}
public zip(Empty x, Empty y) { return new Empty(); }
/*public zip(Empty x, Cons y) { return new Empty(); }
public zip(Cons x, Empty y) { return new Empty(); }
public zip(Empty x, Empty y) { return new Empty(); }
*/
/*
Generiert:
Cons zip<T>(Cons(T x, Cons xs), Cons(T y, Cons ys))
Cons zip<T>(Cons(T x, Cons xs), Cons(T y, Empty ys))
Cons zip<T>(Cons(T x, Empty xs), Cons(T y, Cons ys))
Cons zip<T>(Cons(T x, Empty xs), Cons(T y, Empty ys))
*/
}