[ReasonML] Named & optional params

// ::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 ()

 

posted @ 2017-10-28 01:55  Zhentiw  阅读(211)  评论(0编辑  收藏  举报