Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/fsharp/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Cookies Map.tryFind返回null而不是None_Cookies_F# - Fatal编程技术网

Cookies Map.tryFind返回null而不是None

Cookies Map.tryFind返回null而不是None,cookies,f#,Cookies,F#,我有以下脚本 type SetCookie = { NameValue : string * string; Domain : string option; Path : string option; Expires : string option; MaxAge : string option; Secure : bool; // ? no associated value, anything better than bool HttpO

我有以下脚本

type SetCookie = {
    NameValue : string * string;
    Domain : string option;
    Path : string option;
    Expires : string option;
    MaxAge : string option;
    Secure : bool; // ? no associated value, anything better than bool
    HttpOnly : bool; // ? no associated value, anything better than bool
    }

let GetCookie str =
    let allkeyvalues =
        str.Split ';'
        |> Array.map (fun str ->
            match str.Split '=' with
            | [| key |] -> (key.Trim(), "")
            | [| key; value |] -> (key.Trim(), value)
            | _ -> failwith "there's more than one '='; the format is incorrect.")
    let namevalue = allkeyvalues.[0]
    let attributes =
        Seq.skip 1 allkeyvalues
        |> Seq.map (fun (key, value) ->
            (key.ToLower(), value)) // attribute names are case-insensitive
        |> Map.ofSeq
    {
        NameValue = namevalue
        Domain = Map.tryFind "domain" attributes
        Path = Map.tryFind "path" attributes
        Expires = Map.tryFind "expires" attributes
        MaxAge = Map.tryFind "maxage" attributes
        Secure = Map.containsKey "secure" attributes
        HttpOnly = Map.containsKey "httponly" attributes
    }
但是,函数调用

GetCookie "XXX=YYY; path=/" 
域返回null,过期。。。。和所有其他选项类型,而不是“无”。根据文档,如果找不到,它应该不返回


F None值实际上由.NET null表示。在这样的情况下会出现这种情况,即您以通用方式打印它,但在其他情况下,它只是一个表示细节。通过注释没有参数的联合案例,您可以为自己的有区别的联合实际获得这种行为。

F None值实际上由.NET null表示。在这样的情况下会出现这种情况,即您以通用方式打印它,但在其他情况下,它只是一个表示细节。实际上,您可以通过注释一个没有参数的联合案例来获得您自己的有区别的联合的这种行为。

F规范声明,没有使用null表示:

5.4.8零度

以null作为表示值的类型。这些类型不允许 空文本,但使用空值作为表示形式

对于这些类型,不直接使用null文本 被允许但是,该类型的一个或所有“正常”值是 由空值表示。以下类型在本文件中 类别:

具有 Microsoft.FSharp.Core.CompilationRepresentationCompilationRepresentationFlags.UseNullAsTrueValue 属性标志和单个空联合大小写。空值表示 这个案子。特别是,null在F选项中表示无 类型


F规范规定,使用null表示无:

5.4.8零度

以null作为表示值的类型。这些类型不允许 空文本,但使用空值作为表示形式

对于这些类型,不直接使用null文本 被允许但是,该类型的一个或所有“正常”值是 由空值表示。以下类型在本文件中 类别:

具有 Microsoft.FSharp.Core.CompilationRepresentationCompilationRepresentationFlags.UseNullAsTrueValue 属性标志和单个空联合大小写。空值表示 这个案子。特别是,null在F选项中表示无 类型

  {NameValue =
    ("XXX", "YYY");
   Domain = null;
   Path = Some "/";
   Expires = null;
   MaxAge = null;
   Secure = false;
   HttpOnly = false;}