Created
April 25, 2019 17:56
-
-
Save Schmavery/e405fdae0e2f9f2e54f5b84c44294cb0 to your computer and use it in GitHub Desktop.
"test cases" and notes for backwards-compatible partial application warning
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (** function definition **) | |
| let foo = (fun a b -> a + b)[@num_args 2] | |
| let foo = (fun a b -> a + b) | |
| (* is equivalent to *) | |
| let foo = (fun a -> (fun b -> a + b)[@num_args 1])[@num_args 1] | |
| (** function application **) | |
| foo 1 (* ok *) | |
| foo 1 2 (* ok *) | |
| (foo 1 2)[@fully_applied] (* ok *) | |
| (foo 1)[@fully_applied] (* warning: foo is partially applied *) | |
| (* | |
| Dream reason syntax: | |
| let foo = (a, b) => a + b // automatically adds definition-site annotation | |
| foo(a, b) // automatically adds call-site annotation | |
| foo%(a, b) // "partially applies foo", doesn't apply the annotation | |
| "How it works" | |
| - Functions carry a "how many args before they're fully applied" number | |
| - When functions are partially applied, decrement this number. When it goes to zero, it's fully applied. | |
| - This still allows for higher order functions | |
| Open questions: | |
| - Can we infer the definition-site annotation in the parser? | |
| - What happens when you "more than fully apply" a function? (Aka pass args to the return value of a higher-order function). | |
| - This probably should throw a different warning when when the application has the [@fully_applied] annotation | |
| - Are there cases where this can't be backward compatible/doesn't work? | |
| - Eh what do functions look like in the ocaml typechecker anyway tbd | |
| - Could this help with optional args or would that break backwards compatibility and in what way? | |
| - Can we take advantage of this to improve the syntax of reason pretty printing? | |
| - aka be able to show ('a, 'b) => ('c) => int rather than always collapsing to ('a, 'b, 'c) => int. | |
| *) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment