Omitting eta-expansion gives a wrong answer

"[email protected] [ocaml_beginners]" <[email protected]> 26 Aug 2016 04:13:28 -0700
Newsgroups gmane.comp.lang.ocaml.beginners
Message-ID <[email protected]>
There are well-known situations in OCaml where the programmer must write some eta-expansion by hand to get what he wants (for example, see FAQ - Core language) http://caml.inria.fr/resources/doc/faq/core.en.html#eta-expansion 
 
 FAQ - Core language http://caml.inria.fr/resources/doc/faq/core.en.html#eta-expansion You imperatively need to enclose between parens a pattern matching which is writt...
 
 
 
 View on caml.inria.fr http://caml.inria.fr/resources/doc/faq/core.en.html#eta-expansion 
 Preview by Yahoo 
 
 

Recently, I encountered an example where not writing the eta-expansion 
results not in a type error, but in a wrong answer! I have never seen this mentioned in the manual or elsewhere, and I'm curious to know if anyone has more feedback on this (in particular, can anyone explain in detail what makes the Ocaml interpreter give a wrong answer ?)

Consider the following code snippet :

let jimmy x=
  let _=(print_string"Hello I am Jimmy\n";flush stdout) in
  true;;

let bart x=
  let _=(print_string"Hello I am Bart\n";flush stdout) in
  true;;
  

let decider=ref(false);;

let jimmy_or_bart t=
  if (!decider)
  then jimmy t
  else bart t;;

let example1=jimmy_or_bart ();;
decider:=true;;
let example2=jimmy_or_bart ();; 

 As expected, the computation of example1 will output "I am Bart" and 

 and example2 "I am Jimmy". But if you remove the eta-expansion in the definition of jimmy_or_bart :
 

 

 

 let jimmy_or_bart=
  if (!decider)
  then jimmy
  else bart;;
 

 then both examples will output 
"I am Bart".