Inline function with parentheses or without?


#1

Hi all
I have the following code snippet:

let reqSecurity = (config: Config.env) =>
  Security.query
  |> Js.Promise.then_((p: Security.pool) => {
       let url: string =
         config.url ++ "/sink/resources/users/" ++ p.subject ++ "/coins";
       let httpHeader =
         Axios.makeConfigWithUrl(
           ~url,
           ~_method="GET",
           ~headers={"Authorization": "Bearer " ++ p.token},
           (),
         );
       Axios.request(httpHeader);
     });

The inline function ((p: Security.pool) => {, when I would omit the parentheses, then the compiler complains. Why?
What is the difference between with and without parentheses?

Thanks


#2

let f = a : b => ... here b annotates the return type of the function.
let f = (a : b) => ... here b annotates the type of the argument a.

Reason # let f = a : int => "f";
Error: This expression has type string but an expression was expected of type
         int
Reason # let f = (a : int) => "f";
let f: int => string = <fun>;

#3

In general you can trust refmt to remove all extraneous parentheses. So write it with extra if you want, and refmt will remove them when possible.