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

8735Re: "ocaml_beginners"::[] Choosing the order of parameters

Expand Messages
  • Peng Zang
    Oct 1, 2007
    • 0 Attachment
      -----BEGIN PGP SIGNED MESSAGE-----
      Hash: SHA1

      Ahh, right. So in func2 the function is explictly defined in two parts and so
      there is actual partial application. I thought about why ocaml doesn't do
      this by default but it makes sense as then the timing of any side-effects in
      your functions would be ambiguous. Thanks for the example,

      Peng

      On Monday 01 October 2007 02:35, dmitry grebeniuk wrote:
      > Hello, Peng.
      >
      > PZ> Apropo partial application, I didn't think ocaml
      > PZ> did partial application... I mean you can always
      > PZ> give a function fewer arguments than it takes and
      > PZ> ocaml will return a function with the remaining
      > PZ> arguments but I didn't think ocaml did any thing
      > PZ> (ie. evaluation/calculation) with the arguments
      > PZ> that it has gotten. I thought it just held the
      > PZ> arguments it has until it has all the arguments
      > PZ> at which point, the function is then evaluated.
      >
      > That's not totally right. Try to run the following
      > code and get the difference between partial applications:
      >
      > ======================================================
      > let func1 () () =
      > print_string "func1: fully applied\n";;
      > let func2 () =
      > let () = print_string "func2: partially applied\n" in
      > fun () -> print_string "func2: fully applied\n";;
      > let _ =
      > print_string "1\n";
      > let p1 = func1 () in
      > print_string "2\n";
      > p1 ();
      > print_string "3\n";
      > let p2 = func2 () in
      > print_string "4\n";
      > p2 ();
      > print_string "5\n";;
      > ======================================================
      >
      > Sometimes this difference is useful, it's like a
      > "poor men's OOP": you can do some init-stuff when
      > partially applying first argument(s), and then use
      > resulting closure.
      > But it's not a good style of programming, imho.
      -----BEGIN PGP SIGNATURE-----
      Version: GnuPG v2.0.2 (GNU/Linux)

      iD8DBQFHANmofIRcEFL/JewRAovCAKCUrRlWKH9VvXaBDb7PipaQc48UcgCgt+Pd
      ISkPFRf40SS2qB24kbHBHnE=
      =Cwrw
      -----END PGP SIGNATURE-----
    • Show all 18 messages in this topic