40 lines
862 B
Java
40 lines
862 B
Java
//package de.dhbwstuttgart;
|
|
|
|
import java.lang.Integer;
|
|
import java.lang.IO;
|
|
|
|
public sealed interface IntList permits Empty, Cons{}
|
|
public record Empty() implements IntList {}
|
|
public record Cons(Integer a, IntList rest) implements IntList {}
|
|
|
|
public class Bug406 {
|
|
|
|
public head(Empty()) {
|
|
return -1;
|
|
}
|
|
public head(Cons(e,r)) {
|
|
return e;
|
|
}
|
|
|
|
public append(Empty(), ys) {
|
|
return ys;
|
|
}
|
|
public append(Cons(x, xs), IntList ys) {
|
|
return new Cons(x, append(xs, ys));
|
|
}
|
|
|
|
public add(x, y) {
|
|
return x + y;
|
|
}
|
|
|
|
public static main(args) {
|
|
|
|
var list1 = new Cons(1, new Cons(2, new Cons(3, new Empty())));
|
|
var list2 = new Cons(4, new Cons(5, new Cons(6, new Empty())));
|
|
|
|
IO.println(new Bug406().add(1, 2));
|
|
IO.println(new Bug406().append(list1, list2));
|
|
}
|
|
}
|
|
|