F# keyword 'Some' - what does it mean?
相关问题
- F#: Storing and mapping a list of functions
- Multiplying a list of tuples by a tuple in F#
- Multiplying a string in F#
- F# odd pattern matching issues
- Why doesn't bindingRedirect affect FSharp.Core
相关文章
- es 单字段多分词器时,textField.keyword无法高亮
- FSharp.Data.JsonProvider - Getting json from types
- Signing an F# Assembly (Strong name component)
- Learning F#: What books using other programming la
- fsc.exe is very slow because it tries to access cr
- Extension methods for specific generic types
- F# Object Initialization with a Constructor
- F# Lazy Evaluation vs Non-Lazy
Can check out Discriminated Unions in F# for more info on DUs in general and the option type (Some, None) in particular. As a previous answer says, Some is just a union-case of the option<'a> type, which is a particularly common/useful example of an algebraic data type.
Some
is not a keyword. There is anoption
type however, which is a discriminated union containing two things:Some
which holds a value of some type.None
which represents lack of value.It's defined as:
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.
Some
is used to specify an option type, or in other words, a type that may or may not exist.F# is different from most languages in that control flow is mostly done through pattern matching as opposed to traditional if/else logic.
In traditional if/else logic, you may see something like this:
With pattern matching logic, matching we need a similar way to execute certain code if a value is null, or in F# syntax,
None
Thus we would have the same code as