Хорошо, я делаю макет распределенной системы.каждый экземпляр mClass (объекта) используется 1 потоком.Изменяемые данные не могут быть переданы между объектами mClass. Это пример кода, аналогичного тому, что у меня есть:
type mClass (mID:id)=
member this.ID=mID
let resolve : id->mClass =... //This function turns IDs into the objects they represnt
...
let managementInfo = ref Some mutableData
//this should only ever be called by the GiveControl method.
private member this.TakeControl (frozenData) =
let defrostedData = ... //a variable that works out the unfrozen version of the frozenData
managementInfo := Some defrostedData
///This is a helper that ensure that when ever someone else is told to take control
///that all my internal data and any functions i need to call to tell others are done
///And convert the data a nonmutable form
///(Mutable data can not be tranfered between different instances of of mClass (objects),
///as this is a mockup of a distributed system, where the instances of mClass can't
///@param: nID this ID of the object we are giving control to
///@param: callbacks: a list of functions to call to tell other objects i've given control
private member this.GiveControl nID (callbacks: list<id->unit>) =
let updateInternalData = ... //A function to upate my internal state
updateInternalData;
ignore (List.map (fun f-> f nID) callbacks);
let freezeData data= ... //a function make our mutableData into nonmutable data
let frozenData = (!managemenInfo).Value|>freezeData
managemenInfo:=None;
(nID|>resolve).TakeControl (frozenData)
...
закрытый член this.GiveControl был первоначально объявлен: let giveControl, но это заставило компилятор жаловаться на ошибку- объявление нового типа, пока я не изменил его на частный метод.
Вопрос в том, как я могу переформулировать этот код, чтобы объединить два метода в один.(или, по крайней мере, заставьте GiveControl вызываться только изнутри этого объекта (как бы настоящего частного), а TakeControl вызываться только из GiveControl)