Comment

Comment by edwcross

OCaml has had labeled arguments for decades, so I assumed other languages would have added something similar by now. In C-style, it would be like:

  createUser(user, ~isAdmin:true, ~sendWelcomeEmail:false)
Even though in OCaml's functional style it is actually like this:

  createUser user ~isAdmin:true ~sendWelcomeEmail:false
Using the fact that a variable named exactly like a labeled argument is automatically assigned to it, we can make the call more concise (especially if reusing existing variables):

  let isAdmin = true in
  let sendWelcomeEmail = false in
  createUser user ~isAdmin ~sendWelcomeEmail
parent edwcross 5 months ago

Discussion

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton