typed icon indicating copy to clipboard operation
typed copied to clipboard

Found some problems (maybe) while playing curryings.

Open yhm-amber opened this issue 6 months ago • 3 comments

S31221-09353570_io github forkmaintainers iceraven

S31221-10492213_io github forkmaintainers iceraven

  1. If I want to return a function (closure), I must put it in a bracket when this function is a typed function.
  2. I cannot return a typed function inner a typed function.

And ... how to write a closure/function's type with typed ?

yhm-amber avatar Dec 21 '23 02:12 yhm-amber

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>

moodymudskipper avatar Dec 21 '23 15:12 moodymudskipper

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.

moodymudskipper avatar Dec 21 '23 15:12 moodymudskipper

Before that we also have a bug due to modify_qm_calls() not recursing (calling ? when finding typed nested functions.

moodymudskipper avatar Dec 21 '23 15:12 moodymudskipper