3 ms·
> Imagine the function "fn bar(x: fn(x: int) -> string)", would that be more clear with a colon? In your example, why bother naming the inner "x" variable for
by willtim 5y ago
> Imagine the function "fn bar(x: fn(x: int) -> string)", would that be more clear with a colon?
In your example, why bother naming the inner "x" variable for the function param? It cannot be used on the right-hand-side (definition of "bar"). For that reason, the notation is not exactly "clear". In OCaml the annotation would be:
bar( x : int -> string )
- east2west 5y agoIn Rust you can write ```f: fn(i32) -> i32```. Ocaml's syntax is more consistent, I agree, but its colon operator has different precedence than in Rust, so I am not sure its rational applies to Rust.