码迷,mamicode.com
首页 > 其他好文 > 详细

[ReasonML] Named & optional params

时间:2017-10-28 11:07:40      阅读:220      评论:0      收藏:0      [点我收藏+]

标签:nbsp   output   call   where   function   col   put   amp   fun   

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

 

[ReasonML] Named & optional params

标签:nbsp   output   call   where   function   col   put   amp   fun   

原文地址:http://www.cnblogs.com/Answer1215/p/7745827.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!