Skip to content
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

Type inference could be more flexible #51

Open
nickbattle opened this issue May 29, 2021 · 0 comments
Open

Type inference could be more flexible #51

nickbattle opened this issue May 29, 2021 · 0 comments
Assignees

Comments

@nickbattle
Copy link
Owner

Consider the following:

	f[@T]: @T * @T -> nat
	f(a, b) == a + b
	pre is_real(a) and is_real(b);

This is type clean, and allows a pair of any type of number to be added (since a "nat" number is a real too). Without the precondition, the type checker cannot know that the parameters are numeric, and you get errors:

Error 3139: Left hand of + is not numeric in 'DEFAULT' (test.vdm) at line 3:18
Actual: @T
Error 3140: Right hand of + is not numeric in 'DEFAULT' (test.vdm) at line 3:18
Actual: @T

This is fine. But if the function is more complex, perhaps passing a map @T to @T, it would be nice to be able to say that part of this type is numeric, so that the function can add those parts. But if you say is_(rng m, real) the type inference cannot work out that the @T parameter is a map of ? to real:

	f[@T]: map @T to @T -> nat
	f(m) == m(1) + m(2)
	pre is_real(dom m) and is_real(rng m);

Error 3139: Left hand of + is not numeric in 'DEFAULT' (test.vdm) at line 3:18
Actual: @T
Error 3140: Right hand of + is not numeric in 'DEFAULT' (test.vdm) at line 3:18
Actual: @T
@nickbattle nickbattle self-assigned this May 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant