サンク メモ3

何度も書いているのは、http://d.hatena.ne.jp/itchyny/20130209/1360417348を読んだから。

let rec foldr = T (fun _ (k : Thunk<Thunk<'a> -> Thunk<'b> -> 'b>) (z : Thunk<'b>) (list : Thunk<TList<'a>>) ->
    let rec go xs =
        match eval xs with
        | Nil -> z
        | Cons (y, ys) -> apply (apply k y) (go ys)
    eval (go list))

let k = T (fun _ x ys -> (eval x) :: (eval ys))
let z = T (fun _ -> [])
let list3 = eval (apply (apply (apply foldr k) z) list2)
printfn "%A" list3