This argument cannot be applied without label. Confused, can anyone explain?

Hello everyone,

Can someone explain this to me ?

let log_name = (first_name, ~last_name=?) => {
  switch last_name {
  | None => Console.log2(first_name, "Noname")
  | Some(last_name) => Console.log2(first_name, last_name)
  }
}

let ada = "Ada"

// this is OK
log_name(ada)

// this is OK too
ada->log_name(~last_name="Lovelace")

// this is not OK
ada->log_name()

Error message is:


  We've found a bug for you!
  /.../__tests__/Demo_test.res:34:17

  32 ┆ ada->log_name(~last_name="Lovelace")
  33 ┆ // this is not
  34 ┆ ada->log_name()
  35 ┆
  36 ┆ Assert.pass(~message="OK")

  The function applied to this argument has type
    ('a, ~last_name: 'b=?) => unit
This argument cannot be applied without label

So to answer my newbie question, it works if we write the call without arguments like this:

ada->log_name

I guess otherwise, it means that we pass () (unit) as second argument, hence the failure.

2 Likes

Yes that’s exactly what it means.

1 Like

Working with pipes can be tricky if you aren’t used to it, but once you grok it you will never want to go back.

let fn = str =>
  str
  ->String.trim
  ->String.toUpperCase
1 Like