diff --git a/src/Compiler/Facilities/DiagnosticsLogger.fs b/src/Compiler/Facilities/DiagnosticsLogger.fs index 374a8ddb8bd..f7a15577c64 100644 --- a/src/Compiler/Facilities/DiagnosticsLogger.fs +++ b/src/Compiler/Facilities/DiagnosticsLogger.fs @@ -657,9 +657,8 @@ let CheckNoErrorsAndGetWarnings res = | OkResult (warns, res2) -> Some(warns, res2) | ErrorResult _ -> None -/// The bind in the monad. Stop on first error. Accumulate warnings and continue. [] -let (++) res f = +let bind f res = match res with | OkResult ([], res) -> (* tailcall *) f res | OkResult (warns, res) -> @@ -673,12 +672,12 @@ let (++) res f = let rec IterateD f xs = match xs with | [] -> CompleteD - | h :: t -> f h ++ (fun () -> IterateD f t) + | h :: t -> f h |> bind (fun () -> IterateD f t) [] let rec WhileD gd body = if gd () then - body () ++ (fun () -> WhileD gd body) + body () |> bind (fun () -> WhileD gd body) else CompleteD @@ -686,17 +685,17 @@ let rec WhileD gd body = let rec MapD_loop f acc xs = match xs with | [] -> ResultD(List.rev acc) - | h :: t -> f h ++ (fun x -> MapD_loop f (x :: acc) t) + | h :: t -> f h |> bind (fun x -> MapD_loop f (x :: acc) t) [] let MapD f xs = MapD_loop f [] xs type TrackErrorsBuilder() = - member x.Bind(res, k) = res ++ k + member x.Bind(res, k) = bind k res member x.Return res = ResultD res member x.ReturnFrom res = res member x.For(seq, k) = IterateD k seq - member x.Combine(expr1, expr2) = expr1 ++ expr2 + member x.Combine(expr1, expr2) = bind expr2 expr1 member x.While(gd, k) = WhileD gd k member x.Zero() = CompleteD member x.Delay fn = fun () -> fn () @@ -717,7 +716,7 @@ let IterateIdxD f xs = let rec loop xs i = match xs with | [] -> CompleteD - | h :: t -> f i h ++ (fun () -> loop t (i + 1)) + | h :: t -> f i h |> bind (fun () -> loop t (i + 1)) loop xs 0 @@ -726,7 +725,7 @@ let IterateIdxD f xs = let rec Iterate2D f xs ys = match xs, ys with | [], [] -> CompleteD - | h1 :: t1, h2 :: t2 -> f h1 h2 ++ (fun () -> Iterate2D f t1 t2) + | h1 :: t1, h2 :: t2 -> f h1 h2 |> bind (fun () -> Iterate2D f t1 t2) | _ -> failwith "Iterate2D" /// Keep the warnings, propagate the error to the exception continuation. @@ -742,11 +741,12 @@ let TryD f g = [] let rec RepeatWhileD nDeep body = - body nDeep ++ (fun x -> if x then RepeatWhileD (nDeep + 1) body else CompleteD) + body nDeep + |> bind (fun x -> if x then RepeatWhileD (nDeep + 1) body else CompleteD) [] let inline AtLeastOneD f l = - MapD f l ++ (fun res -> ResultD(List.exists id res)) + MapD f l |> bind (fun res -> ResultD(List.exists id res)) [] let inline AtLeastOne2D f xs ys = @@ -755,7 +755,7 @@ let inline AtLeastOne2D f xs ys = [] let inline MapReduceD mapper zero reducer l = MapD mapper l - ++ (fun res -> + |> bind (fun res -> ResultD( match res with | [] -> zero diff --git a/src/Compiler/Facilities/DiagnosticsLogger.fsi b/src/Compiler/Facilities/DiagnosticsLogger.fsi index 2fe91400fbd..98833e5b473 100644 --- a/src/Compiler/Facilities/DiagnosticsLogger.fsi +++ b/src/Compiler/Facilities/DiagnosticsLogger.fsi @@ -353,7 +353,9 @@ val ResultD: x: 'T -> OperationResult<'T> val CheckNoErrorsAndGetWarnings: res: OperationResult<'T> -> (exn list * 'T) option -val (++): res: OperationResult<'T> -> f: ('T -> OperationResult<'b>) -> OperationResult<'b> +/// The bind in the monad. Stop on first error. Accumulate warnings and continue. +/// Not meant for direct usage. Used in other inlined functions +val bind: f: ('T -> OperationResult<'b>) -> res: OperationResult<'T> -> OperationResult<'b> /// Stop on first error. Accumulate warnings and continue. val IterateD: f: ('T -> OperationResult) -> xs: 'T list -> OperationResult