zl程序教程

您现在的位置是:首页 >  其他

当前栏目

[ReasonML] Named & optional params

amp named optional params
2023-09-14 08:59:17 时间
// ::country is named param
// ::country=?: which make it optional
// because we make ::country=? optional named param, we may pass in or may not pass in
// we need use '()' --> (): string => , which is unit, to call the function
let rock (::country=?) (song: string) (times: int) () :string => 
  switch country {
      | None => {j|Rocked out to $(song) $(times) times somewhere |j}
      | Some g => {j|Rocked out to $(song) $(times) times in $(g) |j};
      };

let output = rock "Nad Tatrou sa blýska" 1 ();  // call ()unit the function
let output2 = rock "Nad Tatrou sa blýska" 1 country::"fff" ();  // pass the country::"China" and then call the function ()