You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It would be nice if the long form anonymous functions would support return type declarations akin to named functions. That is, it'd be nice if the following converted and asserted the return type is T:
julia> function(x, y)::T
return x*y
end
ERROR: syntax: expected "(" in function definition
Note that this appears to work with one argument, but it's bugged and actually applying the type declaration to the argument instead of the function's return:
julia> f =function(x)::Int
x/2end#11 (generic function with 1 method)
julia>f(2.0)
ERROR: MethodError: no method matching (::getfield(Main, Symbol("##11#12")))(::Float64)
Closest candidates are:#11(::Int64) at REPL[41]:2
Stacktrace:
[1] top-level scope at none:0
julia> :(function(x)::Int
x/2end)
:(function (x::Int,)
#= REPL[47]:2 =#
x /2end)
The text was updated successfully, but these errors were encountered:
mbauman
added
bug
Indicates an unexpected problem or unintended behavior
parser
Language parsing and surface syntax
feature
Indicates new feature / enhancement requests
labels
Jul 11, 2019
I get that this is a super-overloaded form, and I get that we're free to parenthesize the names of arguments like (x)::Int, but don't we need an outer set of parentheses for the argument list itself? I'm missing the ambiguity.
It would be nice if the long form anonymous functions would support return type declarations akin to named functions. That is, it'd be nice if the following converted and asserted the return type is
T
:Note that this appears to work with one argument, but it's bugged and actually applying the type declaration to the argument instead of the function's return:
(from https://discourse.julialang.org/t/controlling-the-type-of-anonymous-functions/26264).
The text was updated successfully, but these errors were encountered: