I'll be using Java in this post, but the following also applies to C#, and likely other languages.
We require that submissions must be a first-class function, or a full program to be valid. In Java, many users have started using untyped lambdas as their submission. The problem with untyped lambdas is that they have no meaning without their types.
For example, given a theoretical challenge of Add Two Numbers
, in Java, a submission would look like:
(a,b) -> a + b
which seems relatively reasonable. However, the problem lies with the following solution:
(a,b) -> a.add(b)
The problem with the above statement is that we have absolutely no idea which function is getting called. The only way the above statement could ever work in code is if we say in the description that a
and b
are BigInteger
.
To extend this problem further, lets say I'm answering a sorting challenge. You could submit:
list -> list.sortThis()
Now wait, sortThis()
isn't a function on arrays, or on ArrayList, or anywhere in the JDK. I'd have you tell you that list
is a MutableList
from Eclipse Collections for you to ever use the code. Furthermore, if I did use that code, you don't need to import a MutableList. Java is able to deduce the types, no import needed.
We require the submissions be self-contained, but right now, these lambdas are not self-contained, because they require outside input to indicate the types.
How do we solve this problem?