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

2738Re: "ocaml_beginners"::[] Re: 'ocaml_beginners'::[] Execution semantics

Expand Messages
  • Martin Jambon
    Nov 3, 2004
    • 0 Attachment
      On Wed, 3 Nov 2004, Seth J. Fogarty wrote:

      >
      > On Wed, 3 Nov 2004 21:54:11 -0300 (CLST), andrew cooke
      > <andrew@...> wrote:
      > >
      > > Thanks for the reply.
      > >
      > > Just to get this straight, because i think I wasn't anything like clear
      > > enough (I was not talking about function signatures, but about when
      > > evaluation occurs), are you saying that for the first two examples:
      > >
      > > let f = exampleN 1 2 in
      > > ...
      > > let g = f 3
      >
      > 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
      >
      > I am not certain of the exactly optimizations used for each of these.
      > Technically, yes, the first repeats the work and the second doesn't. I
      > would not be surprised the least if the OCaml compiler optimises them
      > to the same thing. It has done worse voodoo before.

      You guys can play with the hidden counter example. The problem is:
      create a function that takes as argument the first value of a
      counter that should be created internally and returns two functions:
      - one that gives the current value of the counter
      - one that increments the counter

      This function should therefore have the following signature:

      val make_counter : int -> (unit -> int) * (unit -> unit)

      You should then be able to write something like:

      let (get, step) = make_counter 1


      Have fun!

      Martin
    • Show all 26 messages in this topic