@@ -17,12 +17,12 @@ module OptionCE =
1717 Option.bind binder input
1818
1919 // Could not get it to work solely with Source. In loop cases it would potentially match the #seq overload and ask for type annotation
20- member inline this.Bind
21- (
22- m : 'input when 'input : null ,
23- [<InlineIfLambda>] binder : 'input -> 'output option
24- ) : 'output option =
25- this.Bind( Option.ofObj m, binder)
20+ // member inline this.Bind
21+ // (
22+ // m: 'input when 'input: null,
23+ // [<InlineIfLambda>] binder: 'input -> 'output option
24+ // ) : 'output option =
25+ // this.Bind(Option.ofObj m, binder)
2626
2727 member inline this.Zero () : unit option = this.Return()
2828
@@ -71,21 +71,16 @@ module OptionCE =
7171 member inline this.While
7272 (
7373 [<InlineIfLambda>] guard : unit -> bool ,
74- [<InlineIfLambda>] computation : unit -> unit option
74+ [<InlineIfLambda>] generator : unit -> unit option
7575 ) : unit option =
76- if guard () then
77- let mutable whileBuilder = Unchecked.defaultof<_>
78-
79- whileBuilder <-
80- fun () ->
81- this.Bind(
82- this.Run computation,
83- ( fun () -> if guard () then this.Run whileBuilder else this.Zero())
84- )
85-
86- this.Run whileBuilder
87- else
88- this.Zero()
76+
77+ let rec whileBuilder () =
78+ if guard () then
79+ this.Bind( this.Run( fun () -> generator ()), ( fun () -> this.Run( fun () -> whileBuilder ())))
80+ else
81+ this.Zero()
82+
83+ this.Run( fun () -> whileBuilder ())
8984
9085 member inline this.For
9186 (
0 commit comments