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

Re: "ocaml_beginners"::[] Function composition

Expand Messages
  • Hugo Ferreira
    Martin, ... I realized that when Remi Vanicat replied. Sorry about the noise . ... Solution already pointed out by Remi. ... Yes, another option I have.
    Message 1 of 5 , Aug 31, 2005
    • 0 Attachment
      Martin,

      On Wednesday 31 August 2005 19:07, Martin Jambon wrote:
      > On Wed, 31 Aug 2005, Hugo Ferreira wrote:
      > > Hi,
      > >
      > > I am trying to use function compostion using a function that uses no
      > > paremeters.
      > >
      > > The function to be composed is:
      > > # let f1 () = print_string "f1\n" ;;
      > > val f1 : unit -> unit = <fun>
      > >
      > > This next function will use prn to to some task:
      > > # let prn_box prn = print_string "prn: " ; prn () ; ();;
      > > val prn_box : (unit -> 'a) -> unit = <fun>
      > >
      > > When I attempt composition as follows:
      > > # prn_box f1 ;;
      > > prn: f1
      > > - : unit = ()
      > >
      > > But it does not execute. I cannot see why the function is not compete.
      >
      > It does execute prn_box and f1, what's wrong?

      I realized that when Remi Vanicat replied. Sorry about the "noise".

      > If you want to create a function which calls prn_box with prn as argument,
      > you would do this:
      >
      > (* let prn_f1 = *) fun () -> prn_box f1
      >
      > > I can also not see why
      > > val prn_box : (unit -> 'a) -> unit = <fun>
      > > nor how to make it:
      > > val prn_box : (unit -> unit) -> unit = <fun>
      >
      > That's not a big problem. In practice, either you define a module
      > interface (usually in a .mli file) which restricts the type of the
      > function, or you add a type constraint on the return value of prn:
      >
      > # let prn_box prn = print_string "prn: "; (prn () : unit);;
      > val prn_box : (unit -> unit) -> unit = <fun>
      >

      Solution already pointed out by Remi.

      > Or on the return value of prn_box:
      >
      > # let prn_box prn : unit = print_string "prn: "; prn ();;
      > val prn_box : (unit -> unit) -> unit = <fun>
      >

      Yes, another option I have.

      Thanks,
      Hugo Ferreira.


      >
      > Martin
      >
      > > Can anyone explain why/how?
      > >
      > > TIA,
      > > Hugo Ferreira.
      > >
      > >
      > >
      > >
      > > Archives up to August 22, 2005 are also downloadable at
      > > http://www.connettivo.net/cntprojects/ocaml_beginners/ The archives of
      > > the very official ocaml list (the seniors' one) can be found at
      > > http://caml.inria.fr Attachments are banned and you're asked to be
      > > polite, avoid flames etc. Yahoo! Groups Links
      >
      > --
      > Martin Jambon, PhD
      > http://martin.jambon.free.fr
      >
      >
      >
      > Archives up to August 22, 2005 are also downloadable at
      > http://www.connettivo.net/cntprojects/ocaml_beginners/ The archives of the
      > very official ocaml list (the seniors' one) can be found at
      > http://caml.inria.fr Attachments are banned and you're asked to be polite,
      > avoid flames etc. Yahoo! Groups Links
      >
      >
      >
    Your message has been successfully submitted and would be delivered to recipients shortly.