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

functional record update => problems = Bug ?!

Expand Messages
  • Oliver Bandel
    Hello, why is there a problem with add_to_ncl_2 ?! Yesterday I tested another function, and using the fully qualified path to the record-entry gave me an
    Message 1 of 3 , Feb 28, 2006
      Hello,

      why is there a problem with add_to_ncl_2 ?!

      Yesterday I tested another function, and using the fully
      qualified path to the record-entry gave me an error.
      So I decided (after looking in documentations around OCaml)
      to not using it.
      This worked for some functions, but now there is a function,
      where I need the fully qualifying name.

      Why ?


      Is there any rule I have to follow?



      (* =============================================================== *)

      type r_t= {
      mutable ncl: r_t list;
      mutable acl: r_t list;
      }

      (* =============================================================== *)

      let create () = { ncl = []; acl = [] }

      let add_to_ncl_1 rel nch = { rel with ncl = (nch :: rel.ncl) }

      let add_to_ncl_2 rel nch = { rel with ncl = (nch :: ncl) }

      (* =============================================================== *)

      ==========
      first:~ oliver$ ocamlc -i ocaml-bug.ml
      File "ocaml-bug.ml", line 16, characters 56-59:
      Unbound value ncl
      first:~ oliver$
      ==========

      (Line number does not make sense above.)


      Ciao,
      Oliver
    • Oliver Bandel
      ... oooh, I mixed imparative and functional style... :( seems to be the problem. I should decide for one way... Ciao, Oliver
      Message 2 of 3 , Feb 28, 2006
        On Tue, Feb 28, 2006 at 10:29:08PM +0100, Oliver Bandel wrote:
        >
        >
        > Hello,
        >
        > why is there a problem with add_to_ncl_2 ?!
        >
        > Yesterday I tested another function, and using the fully
        > qualified path to the record-entry gave me an error.
        > So I decided (after looking in documentations around OCaml)
        > to not using it.
        > This worked for some functions, but now there is a function,
        > where I need the fully qualifying name.
        >
        > Why ?


        oooh, I mixed imparative and functional style... :(


        seems to be the problem.
        I should decide for one way...


        Ciao,
        Oliver
      • Michael Wohlwend
        ... this works for me: let add_to_ncl_2 rel nch = { rel with ncl = (nch :: rel.ncl) } In the initialisation { expr with field = expr { ; field = expr } }
        Message 3 of 3 , Feb 28, 2006
          On Tuesday 28 February 2006 22:29, Oliver Bandel wrote:
          > Hello,
          >
          > let add_to_ncl_2 rel nch = { rel with ncl = (nch :: ncl) }
          >
          > (* =============================================================== *)

          this works for me:
          let add_to_ncl_2 rel nch = { rel with ncl = (nch :: rel.ncl) }

          In the initialisation
          { expr with field = expr { ; field = expr } }
          the first expr is a record, the other expr are arbitrary expressions, which
          means you must use expr.field to access a record field. That's how I read to
          docu...

          cheers,
          Michael
        Your message has been successfully submitted and would be delivered to recipients shortly.