async icon indicating copy to clipboard operation
async copied to clipboard

Unexpected behaviour change by just opening Async

Open renald opened this issue 2 years ago • 0 comments

Probably very good to explain, but takes me quite by surprise.

I've got the following code:

In bin/main.ml:

let dummy_parser html = print_endline ("I got: >\n" ^ html)

let () =
  if Array.length Sys.argv < 2 then begin
    prerr_endline "Usage: scraper <name>";
    exit 2;
  end; (* if *)
  print_endline "here 1";
  Scraper.scrape_page Sys.argv.(1) dummy_parser`

And in lib/scraper.ml

let scrape_page address html_parser =
  print_endline "Hello?";
  html_parser (address ^ "je!")

after dune exec scraper xyz I get (as expected):

$ dune exec scraper xyz 
here 1
Hello?
I got: >
xyzje!

However, if I add open Async to lib/scraper.ml:

open Async

let scrape_page address html_parser =
  print_endline "Hello?";
  html_parser (address ^ "je!")

then I get:

$ dune exec scraper xyz 
here 1
I got: >
xyzje!

So, the Hello? is not printed.

Probably some optimization is going on, but I still am confused.

renald avatar Mar 01 '22 16:03 renald