diff --git a/resources/bytecode/javFiles/PaternMatchingHaskellStyle.jav b/resources/bytecode/javFiles/PaternMatchingHaskellStyle.jav index ba3e7771..a1283113 100644 --- a/resources/bytecode/javFiles/PaternMatchingHaskellStyle.jav +++ b/resources/bytecode/javFiles/PaternMatchingHaskellStyle.jav @@ -1,14 +1,26 @@ +import java.lang.Boolean; + sealed interface List permits LinkedElem, Elem {} public record LinkedElem(T a, List l) implements List {} public record Elem(T a) implements List {} 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)); - } -} + public append(LinkedElem(a, b), list2) { + if (b instanceof Elem) { + return handleElem(a, (Elem) b, list2); + } else if (b instanceof LinkedElem) { + return handleLinkedElem(a, (LinkedElem) b, list2); + } + return null; + } + + private handleElem(a, Elem(e), list2) { + return new LinkedElem<>(a, new LinkedElem<>(e, list2)); + } + + private handleLinkedElem(a, LinkedElem(a,r), list2) { + return new LinkedElem<>(a, append(r, list2)); + } +} \ No newline at end of file diff --git a/src/test/java/TestComplete.java b/src/test/java/TestComplete.java index 1d314087..26e73bd8 100644 --- a/src/test/java/TestComplete.java +++ b/src/test/java/TestComplete.java @@ -869,11 +869,11 @@ public class TestComplete { var instance = clazz.getDeclaredConstructor().newInstance(); var m = clazz.getDeclaredMethod("append", R, I); - //var x = rctor.newInstance(rctor.newInstance(0, rctor.newInstance(0, r2ctor.newInstance(0))), 0); - //var y = rctor.newInstance(r2ctor.newInstance(0), 0); + var x = rctor.newInstance(rctor.newInstance(0, rctor.newInstance(0, r2ctor.newInstance(0))), r2ctor.newInstance(0)); + var y = rctor.newInstance(r2ctor.newInstance(0), r2ctor.newInstance(0)); - //assertEquals(m.invoke(instance, x, y), 10); - //assertEquals(m.invoke(instance, y, y), 40.0); + assertEquals(m.invoke(instance, x, y), 10); + assertEquals(m.invoke(instance, y, y), 0); }