F# 如何使管道lambda返回一些值
很难解释,以下是我想要的:F# 如何使管道lambda返回一些值,f#,lambda,pipe,F#,Lambda,Pipe,很难解释,以下是我想要的: let internal (=%=) (W : int, thriller : Dev -> unit -> bool) = let id = get W if id <> -1 then workbase.[id] |> thriller 评论后: let CanRead W dev v = match W =%= fun w -> w.GetCanRead dev v with
let internal (=%=) (W : int, thriller : Dev -> unit -> bool) =
let id = get W
if id <> -1 then
workbase.[id] |> thriller
评论后:
let CanRead W dev v = match W =%= fun w -> w.GetCanRead dev v with
| Some(t) -> t
| None -> false
缺少一个else分支
在if/else表达式中返回单位时,如果。。。然后是一个快捷方式,如果。。。然后其他的因此,您始终可以在完整的if/else表达式中返回某些类型T,例如,选项类型如下:
let internal (=%=) (W : int, thriller : Dev -> unit -> bool) =
let id = get W
if id <> -1 then
Some (workbase.[id] |> thriller)
else None
缺少一个else分支
在if/else表达式中返回单位时,如果。。。然后是一个快捷方式,如果。。。然后其他的因此,您始终可以在完整的if/else表达式中返回某些类型T,例如,选项类型如下:
let internal (=%=) (W : int, thriller : Dev -> unit -> bool) =
let id = get W
if id <> -1 then
Some (workbase.[id] |> thriller)
else None
在if-then构造中必须有“else”部分。在任何情况下都必须返回结果。在if-then构造中必须有“else”部分。在任何情况下,它都必须返回一个结果。您不“需要”一个else——您只需要在if语句不返回时才需要它unit@John:您的if表达式。;-]你不需要一个else——你只需要在if语句没有返回时才需要它unit@John:您的if表达式。;-]非常感谢。这正是我需要的选择。谢谢!选项正是我在这里需要的。在您的用法中,更惯用的F是将match opt与| Somet->|None->…在您的用法中,更惯用的F是将match opt与| Somet->|无->。。。