Reputation: 12127
I have a type that receives data through websocket / event and it instantiates a couple other types that also need that data for their work.
I thought it would simplify the code to have only one event listener, in the parent type and pass the result by reference so the children types could access the last data.
I've never used byref in F# and .. looks like I don't get it right
From the parent:
let mutable lastTrade = TradeData.empty // this gets updated through an event
let closeOrderHandler = CloseOrderHandler(coreGuid, instrument, &lastTrade)
and the child object:
type CloseOrderHandler(coreGuid: string, instrument: Instrument, lastTrade: byref<TradeData>) = ...
but this will not compile, I get:
[FS0412] A type instantiation involves a byref type. This is not permitted by the rules of Common IL.
what am I doing wrong?
What I am trying to accomplish is to have one mutable field with results updated by a socket / event and the child types be able to read the last result as they need (their actions are event driven, so they don't always get called from the parent and need to access the latest value as they need).
Upvotes: 0
Views: 284