Loading ...
Sorry, an error occurred while loading the content.

Re: "ocaml_beginners"::[] Re: How to optimize combine-function

Expand Messages
  • Andreas Romeyke
    Hi William, Am Wed, 7 May 2008 10:10:33 -0500 ... Your solution is quite impressive. It is faster than all variants before and does not occupy so much memory.
    Message 1 of 12 , May 8, 2008
    • 0 Attachment
      Hi William,

      Am Wed, 7 May 2008 10:10:33 -0500
      schrieb "William D. Neumann" <wneumann@...>:

      > By the way, I had one of those head slapping moments this morning
      > when I realized that you could use a simple nested fold (essentially
      > what you're doing here) with the filter at the core to generate the
      > final list without needing the prefiltered one (again with the
      > simplified filtering):
      >
      > let combine_2 ll1 ll2 prd =
      > let inner_fold l2 =
      > List.fold_left (fun acc l1 -> let l12 = l1 @ l2 in
      > if prd l12 then l12::acc else acc
      > ) [] ll1
      > in
      > List.fold_left (fun acc l2 -> (inner_fold l2) @ acc) [] ll2
      > ;;
      >
      > Honestly, I'm shocked I didn't come up with this yesterday, as I

      Your solution is quite impressive. It is faster than all variants
      before and does not occupy so much memory.

      The solution is clear and beautiful, too.

      Thank you,

      Bye Andreas

      --
      Software Developer / Dipl. Inform. (FH)
      Max Planck Institute for Human Cognitive and Brain Sciences
      Department of Psychology
      Stephanstr. 1a, 04103 Leipzig, Germany



      [Non-text portions of this message have been removed]
    Your message has been successfully submitted and would be delivered to recipients shortly.