F# keyword 'Some'

前端 未结 3 598
闹比i
闹比i 2021-02-06 21:24

F# keyword \'Some\' - what does it mean?

3条回答
  •  不知归路
    2021-02-06 21:57

    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:

    if (isNull(x)) {
       do ...  
    } else {         //x exists
       do ...  
    }
    

    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

    match x with 
      | None -> do ...
      | Some x -> do ... 
    

提交回复
热议问题