typed
typed copied to clipboard
Found some problems (maybe) while playing curryings.
- If I want to return a function (closure), I must put it in a bracket when this function is a typed function.
- I cannot return a typed function inner a typed function.
And ... how to write a closure/function's type with typed ?
It's not a typed issue but more of a precedence issue, ?
has lower precedence than everything, and a ?
in a non braced function definition just ends the function and the rhs is not part of the function, see below:
library(typed)
#>
#> Attaching package: 'typed'
#> The following object is masked from 'package:utils':
#>
#> ?
lobstr::ast(function(a,b) a + b)
#> █─`function`
#> ├─█─a = ``
#> │ └─b = ``
#> ├─█─`+`
#> │ ├─a
#> │ └─b
#> └─<inline srcref>
lobstr::ast(function(a,b) a ? b)
#> █─`?`
#> ├─█─`function`
#> │ ├─█─a = ``
#> │ │ └─b = ``
#> │ ├─a
#> │ └─<inline srcref>
#> └─b
lobstr::ast(add <- \(a) (Double() ? \(b=?Double()) a + b))
#> █─`<-`
#> ├─add
#> └─█─`function`
#> ├─█─a = ``
#> ├─█─`(`
#> │ └─█─`?`
#> │ ├─█─Double
#> │ └─█─`function`
#> │ ├─█─b = █─`?`
#> │ │ └─█─Double
#> │ ├─█─`+`
#> │ │ ├─a
#> │ │ └─b
#> │ └─<inline srcref>
#> └─<inline srcref>
lobstr::ast(add <- \(a) Double( ) ? \(b=?Double()) a + b)
#> █─`?`
#> ├─█─`<-`
#> │ ├─add
#> │ └─█─`function`
#> │ ├─█─a = ``
#> │ ├─█─Double
#> │ └─<inline srcref>
#> └─█─`function`
#> ├─█─b = █─`?`
#> │ └─█─Double
#> ├─█─`+`
#> │ ├─a
#> │ └─b
#> └─<inline srcref>
The last case however is a bug, I have code that attempts to map ?
to the standard help when it's relevant, and this code is clunky.
Side note, please don't post screen capture but actual code that I can reproduce, to reproduce the above I need to copy the OCRed code and fix it so that makes it harder than necessary.
Before that we also have a bug due to modify_qm_calls()
not recursing (calling ?
when finding typed nested functions.