Untitled
unknown
plain_text
9 months ago
2.1 kB
18
Indexable
public class Solution {
/*
We have a toy language that has different types
We have elementary or primitive types that can look like:
int
str
float
double
Then we have a tuple type that can have at least one element of types in it like:
(int)
(int, str)
((int, int), str, (int, str))
Note that elementary int is different than tuple (int)
There can also be ambigiuous typing which are noted by types that start with a capital T like:
T
T1
T2
These are all represented by class Node
Then we have functions that take in parameter types that are delimited by a semicolon and has a return type
[semicolon separated params] -> return type
[int; int] -> T
[(int, str); str] -> (int, int)
*/
public class Node {
public String getName() {
throw new NotImplementedYetException();
}
public List<Node> getChildren() {
throw new NotImplementedYetException();
}
public String toString() {
throw new NotImplementedYetException();
}
}
public class Func {
public Func(List<Node> params, Node returnType) {
}
public List<Node> getParams() {
throw new NotImplementedYetException();
}
public Node getReturnType() {
throw new NotImplementedYetException();
}
public String toString() {
throw new NotImplementedYetException();
}
}
/*
Let's say we want to invoke a given function Func with a specific set of arguments. Evaluate what the function's return type is based on the invokeArgs, if valid.
If there is a mismatch, throw an error.
*/
public static Node getReturnType(Func func, List<Node> invokeArgs) {
throw new NotImplementedYetException();
}
public static void main(String[] args) {
// write tests here
}
}Editor is loading...
Leave a Comment