F#关键字"Some" [英] F# keyword 'Some'
本文介绍了F#关键字"Some"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
F#关键字"某些"-是什么意思?
F# keyword 'Some' - what does it mean?
推荐答案
Some
不是关键字.但是,有一个option
类型,它是一个包含两个东西的有区别的联合:
Some
is not a keyword. There is an option
type however, which is a discriminated union containing two things:
-
Some
包含某种类型的值. -
None
表示缺乏价值.
Some
which holds a value of some type.None
which represents lack of value.
它的定义是:
type 'a option =
| None
| Some of 'a
它的行为就像是可为空的类型,在这里您想要一个可以保存某种类型的值或根本没有任何值的对象.
It acts kind of like a nullable type, where you want to have an object which can hold a value of some type or have no value at all.
let stringRepresentationOfSomeObject (x : 'a option) =
match x with
| None -> "NONE!"
| Some(t) -> t.ToString()
这篇关于F#关键字"Some"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文