F#引用类型中的选项类型是什么?

时间:2015-07-10 08:29:40

标签: .net f#

是uint64选项类型引用类型还是值类型?我遇到了一些与此相关的性能问题。请澄清。

2 个答案:

答案 0 :(得分:4)

由于None隐式表示为nullOption是引用类型。

F#规范给出了以下定义,该选项要求选项为引用类型:

[<DefaultAugmentation(false)>]
[<CompilationRepresentation(CompilationRepresentationFlags.UseNullAsTrueValue)>]    
type 'T option =
    | None 
    | Some of 'T
    static member None : 'T option
    static member Some : 'T -> 'T option
    [<CompilationRepresentation(CompilationRepresentationFlags.Instance)>]
    member Value : 'T
    member IsSome : bool
    member IsNone : bool    

答案 1 :(得分:0)

public class RefactorMe {

  private static List<Event<Apple>> mAppleEventList = new ArrayList<Event<Apple>>();
  private static List<Event<Banana>> mBananaEventList = new ArrayList<Event<Banana>>();
  private static List<Event<Orange>> mOrangeEventList = new ArrayList<Event<Orange>>();

  public static List<Event<Apple>> getAppleList() {
    return mAppleEventList;
  }

  public static List<Event<Banana>> getBananaEventList() {
    return mBananaEventList;
  }

  public static List<Event<Orange> getOrangeList() {
    return mOrangeEventList;
  }

  public static void addAppleEvent(Event<Apple> pEvent) {
    mAppleEventList.add(pEvent);
  }

  public static void addBananaEvent(Event<Banana> pEvent) {
    mBananaEventList.add(pEvent);
  }

  public static void addOrangeEvent(Event<Orange> pEvent) {
    mOrangeEventList.add(pEvent);
  }

}
来自FSharp Source Code

表明这是一种参考类型。