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

2734Re: "ocaml_beginners"::[] Execution semantics

Expand Messages
  • Issac Trotts
    Nov 3, 2004
      On Nov 3, 2004, at 11:03 AM, andrew cooke wrote:

      > Where can I find a clear description of how OCaml executes code. In
      > particular, I want to understand when functions with several values are
      > evaluated - is the evaluation progressive (during Currying) or is
      > evaluation delayed until all arguments are present.
      >
      > For example, are the following equivalent, always?
      >
      > let example1 a b x =
      > let a' = f1 a in
      > let b' = f2 b in
      > f3 a' b' x
      >
      > let example2 a b =
      > let a' = f1 a in
      > let b' = f2 b in
      > fun x -> f3 a' b' x
      >
      > let example3 x a b =
      > let a' = f1 a in
      > let b' = f2 b in
      > f3 a' b' x

      No, for example

      # let f1 x = x;;
      val f1 : 'a -> 'a = <fun>
      # let f2 x = -x;;
      val f2 : int -> int = <fun>
      # let example1 a b x =
      let a' = f1 a in
      let b' = f2 b in
      f3 a' b' x;;
      val example1 : 'a -> int -> 'b -> 'a * int * 'b = <fun>
      # let example2 a b =
      let a' = f1 a in
      let b' = f 2 b in
      fun x -> f3 a' b' x ;;
      val example2 : 'a -> int -> 'b -> 'a * int * 'b = <fun>
      # let example3 x a b =
      let a' = f1 a in
      let b' = f2 b in
      f3 a' b' x;;
      val example3 : 'a -> 'b -> int -> 'b * int * 'a = <fun>
      # example1 1 2 3;;
      - : int * int * int = (1, -2, 3)
      # example2 1 2 3;;
      - : int * int * int = (1, -2, 3)
      # example3 1 2 3;;
      - : int * int * int = (2, -3, 1)

      -----
      Issac Trotts
      Programmer, NIMH Human Brain Project
      University of California, Davis
      http://mallorn.ucdavis.edu/conexus
    • Show all 26 messages in this topic