F#如何编写空语句 [英] F# how to write an empty statement

查看:106
本文介绍了F#如何编写空语句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在F#中编写无操作语句?

How can I write a no-op statement in F#?

具体来说,我该如何改进以下match语句的第二个子句:

Specifically, how can I improve the second clause of the following match statement:

match list with
    | [] -> printfn "Empty!"
    | _ -> ignore 0

推荐答案

使用单位产生空洞的副作用:

Use unit for empty side effect:

match list with
  | [] -> printfn "Empty!"
  | _ -> ()

这篇关于F#如何编写空语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆