I think this is because the fun inside f1
is immediately invoked with arguments that are in scope so it is transformed into a case
expression by the compiler. I know such optimization exists but I cannot find the article or changelog where it is described.
See Immediately-called funs optimization (looking for docs) .