-
Notifications
You must be signed in to change notification settings - Fork 4
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
declare()
type hints
#169
Comments
A few of my own thoughts are below, from when I was thinking about this myself: Possibly the declarations should be one level deeper for clarity of what we're actually declaring, though I guess this depends on if the intention is for declare(type(a = integer(1))) Allowing for literals would be good: declare(type(a = "abc" | 4 | 5 | FALSE)) Creating new named types from e.g. type unions would also be good. In this example I use declare(type(my_type <- integer(5) | FALSE ))
declare(type(a = my_type)) Also, type generics would be really nice. Here, I use declare(type(maybe <- (U -> U | FALSE)))
# declare(type(bar = integer(1) | FALSE))
declare(type(bar = maybe(integer(1)))) One can imagine a combination of type generics and function definitions: declare(type(
wrapper <- (U -> function(U) { list(U) })
))
declare(type(
fn = wrapper(integer(1))
))
fn <- function(x) {
list(x + 1L)
} Also, should other attributes be possible to declare? declare(type(list(3), names = c("abc", "def", "ghi"), class = "myclass")) |
Do you imagine one call like What do you think of: declare(
name1 = type(...),
name2 = type(...),
...,
return = type(...)
) Regarding the last question about attributes, I think it's a good idea. This could be supported with this approach too, like: declare(
time = type(double(), class = "POSIXct", tz = NULL | character(1)),
name2 = type(...),
name3 = type(...)
) Ideally, all this would work nicely with S7, so one could do: declare(
time = type(S7::class_POSIXct)
) |
The |
It would be nice to use
declare()
for type hints, following the style of a Fortran subroutine type manifest. These type declarations could then:Example syntax:
Some additional, more experimental syntax could also be supported:
NULL
able) args:Include a way to specify function parameters and their expected signatures:
For multidimensional arrays, allow naming dimensions for clarity :
The text was updated successfully, but these errors were encountered: