Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I suspect the performance problem you are seeing is due to the block memory zeroing involved when cloning the record (plus a negligible time for allocating it and subsequently garbage collecting it) in every iteration of the loop. You could rewrite your example using a struct:</p> <pre><code>[&lt;Struct&gt;] type DeviceStatus = val RPM : int val Pressure : int val Temperature : int new(rpm:int, pres:int, temp:int) = { RPM = rpm; Pressure = pres; Temperature = temp } let rec UpdateStatusITimes (status:DeviceStatus) (i:int) = match i with | 0 -&gt; status | _ -&gt; UpdateStatusITimes (DeviceStatus(90, status.Pressure, status.Temperature)) (i - 1) let initStatus = DeviceStatus(80, 100, 70) </code></pre> <p>The performance will now be close to that of using global mutable variables or by redefining <code>UpdateStatusITimes status i</code> as <code>UpdateStatusITimes rpm pres temp i</code>. This will only work if your struct is no more than 16 bytes long as otherwise it will get copied in the same sluggish manner as the record.</p> <p>If, as you've hinted at in your comments, you intend to use this as part of a shared-memory multi-threaded design then you will need mutability at some point. Your choices are a) a shared mutable variable for each parameter b) one shared mutable variable containing a struct or c) a shared facade object containing mutable fields (like in ildjarn's answer). I would go for the last one since it is nicely encapsulated and scales beyond four int fields.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload