It came up in Do-Block Syntax with Where Keyword - #16 by sgaure whether it was possible to use type variables in anonymous functions created with the do
syntax. Although I do not think it would solve the particular problem there, and otherwise will be of limited utility, it would be nice to have just to be complete.
I looked into it. It turns out it can be enabled with a one-line change in the parse_do
function in JuliaSyntax/src/parser.jl
:
2308c2308
< emit(ps, m, K"tuple")
---
> peek_behind(ps).kind != K"where" && emit(ps, m, K"tuple")
It will require the do
-argument list to be enclosed in parentheses:
foreach([1, 2.0, "foo", false]) do (x::T) where T
println(T)
end
Int64
Float64
String
Bool
Since a where
clause in a do
argument list currently leads to a syntax error, I doubt this will break anything. What do people think?