Ocaml语法效率

0 syntax ocaml

所以这是一周中每天的用户定义数据类型日(即:星期日,星期一等)

let is_weekend_day (d:day) : bool = 
   begin match d with
     | Sunday -> true
     | Saturday -> true 
     | _ -> false
   end
Run Code Online (Sandbox Code Playgroud)

有没有办法压缩代码?

ie: Sunday || Saturday -> true 

the problem with this is that it's not in syntax, but having 2 additional       
lines seems like such a waste of space!
Run Code Online (Sandbox Code Playgroud)

Éti*_*lon 5

您可以使用|(称为or-pattern)组合模式.

通过使用它并删除多余的类型注释并开始/结束,您将获得以下内容:

let is_weekend_day d = 
   match d with
     | Sunday | Saturday -> true 
     | _ -> false
Run Code Online (Sandbox Code Playgroud)