25 lines
718 B
Java
25 lines
718 B
Java
import java.lang.Object;
|
|
import List;
|
|
import Cons;
|
|
import Empty;
|
|
import Pair;
|
|
|
|
public class PatternMatchingJava {
|
|
public <A, B> Cons<Pair<A, B>> zip(Cons<A> a, Cons<B> b) {
|
|
switch (a) {
|
|
case Cons(x, Cons xs) -> {
|
|
switch (b) {
|
|
case Cons(y, Cons ys) -> { return new Cons<>(new Pair<>(x, y), zip(xs, ys)); }
|
|
};
|
|
}
|
|
case Cons(x, Empty xs) -> {
|
|
switch (b) {
|
|
case Cons(y, Empty ys) -> { return new Cons<>(new Pair<>(x, y), zip(xs, ys)); }
|
|
};
|
|
}
|
|
};
|
|
}
|
|
public <A, B> Empty<Pair<A, B>> zip(Empty<A> a, Empty<B>) {
|
|
return new Empty<>();
|
|
}
|
|
} |