The problem is in the implementation of appendLogs
function. There, you don't use the tpl
parameter, but use the outer scope's vl
instead, which contains only value and log for the current part of computation. You also need to flip arguments for List.append
, otherwise the log will be backwards.
With both these fixes, your function would look like this:
let appendLogs logs tpl =
let value = tpl |> fst
let log = tpl |> snd
(value, log |> List.append logs)
And with this you should get the expected result.
I also would like to add that by using destructuring in the first method parameter and later in a let
binding, your Bind
function could be implemented somewhat simpler:
member this.Bind((x, log) : 'a * string list, f) =
let y, nextLog = f x
y, List.append log nextLog