RedPRL / ocaml-bwd

🔙 Backward lists for OCaml
https://ocaml.org/p/bwd
Apache License 2.0
19 stars 2 forks source link

feat: add back `concat` and `flatten` #19

Closed favonia closed 11 months ago

favonia commented 11 months ago

Close #18. My hesitation is whether the complex code to make it tail-recursive is worth it:

let concat bs =
  let[@tail_mod_cons] rec go bs =
    function
    | Emp ->
      begin
        match bs with
        | Emp -> Emp
        | Snoc (bs, b) -> (go[@tailcall]) bs b
      end
    | Snoc (xs, x) ->
      Snoc ((go[@tailcall]) bs xs, x)
  in
  go bs Emp
favonia commented 11 months ago

Actually, I might found a possibly better way to write my code without using concat. Let me close this PR for now.