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

Re: "ocaml_beginners"::[] trying to understand the use of keyword "with"

Expand Messages
  • Lukasz Stafiniak
    On Thu, Jul 18, 2013 at 12:09 AM, Jean Saint-Remy ... all of: a string, an int and a float. Using the syntax {acc with pos = {symbol= x ; holding=42;
    Message 1 of 2 , Jul 17, 2013
    • 0 Attachment
      On Thu, Jul 18, 2013 at 12:09 AM, Jean Saint-Remy
      <jeansaintremy@...>wrote:

      > **
      >
      >
      > Hi,
      >
      > I'm having difficulties understanding the keyword "with" in the following
      > code. I have searched in the manual and came upon exception syntax. It
      > appears the force of "with" is the same as in matching. Would you be so
      > kind and explain the syntax in greater detail?
      >
      > Thanks,
      >
      > jean
      >
      > type position = { symbol : string; holding : int; pprice : float; } ;;
      > type account = { name : string; max_ind_holding : float; pos : position
      > list; } ;;
      >
      > The field "pos" stores a list of records, each record in the list stores
      all of: a string, an int and a float. Using the syntax

      {acc with pos = {symbol="x"; holding=42; pprice=3.14}::acc.pos}

      you create a value almost the same as "acc" but with "pos" field containing
      a list with one additional record in front. The record contains all of "x",
      42 and 3.14 (as it must contain exactly three fields).


      [Non-text portions of this message have been removed]
    Your message has been successfully submitted and would be delivered to recipients shortly.