-
Notifications
You must be signed in to change notification settings - Fork 38
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
rtype --> predicate parser/compiler #62
Comments
No time at the moment. We have the big open issue for runtime type checking in our project at work. But I can’t predict when we get down to it. |
Is this example correct? parseSignature('Number => String') => {
checkInputs: function isNumber(value) {
return typeof value === 'number';
},
checkOutput: function isString(value) {
return typeof value === 'string';
},
checkError: () => true // no errors defined in signature
} |
@maiermic What does that look like with multiple arguments? =) I think there are still some open questions here:
|
Good questions.
|
How about this example with two parameters? function isNumber(value) {
return typeof value === 'number';
}
function isString(value) {
return typeof value === 'string';
}
parseSignature('(Number, String) => String') => {
checkInputs(...inputs) {
return isNumber(inputs[0]) && isString(inputs[1]);
},
checkOutput: isString,
checkError: () => true // no errors defined in signature
} |
The current suggestion for parseSignature(signature: String) => TypeChecker Regarding separation of concerns: How about splitting the functionality (signature parsing and generation of parseSignature(signature: String) => RTypeAST
generateTypeChecker(signature: RTypeAST) => TypeChecker |
Good suggestion. We should do that. We should also make the type checking functions return an array of |
Write a function that takes an rtype interface description as a string and returns an object that can be used for runtime type checking.
The target function will get wrapped by a utility such as rfx. When the wrapper function gets called, it will pass inputs to
checkInputs()
. If it returns true, only then does the original function get called. When the function returns, its output will be similarly checked bycheckOutput()
before it gets returned to the original caller. If the function throws, the error will also be checked, bycheckError()
.Useful background:
If you're curious about types, see the introduction to types from the Stanford Compiler course.
Contributing
Start with unit tests, please. See Why I Use Tape Instead of Mocha & So Should You & Five Questions Every Unit Test Must Answer for guidance on how to write a good unit test suite.
Related issues:
interfaces.rtype
file #61The text was updated successfully, but these errors were encountered: