I have a application which runs as a server, dose some calculations and returns a value. I have created a discriminated union type of MessageType
so I can have different types of messages passed between applications.
The MessageType
is made up of an ExchangeMessage
of type ExchangeFrame
. The question I have is how to access the values of ExchangeFrame
from the MessageType
.
The code might explain it better
[<CLIMutable>]
type ExchangeFrame =
{
FrameType: FrameType
Amount: double;
ConvertTo: Currency
ConvertFrom: Currency
}
type MessageType = ExchangeMessage of ExchangeFrame
let server () =
use context = new Context()
// socket to talk to clients
use responder = context |> Context.rep
"tcp://*:5555" |> Socket.bind responder
Console.WriteLine("Server Running")
while true do
// wait for next request from client
let messageReceived = responder |> Socket.recv |> decode |> deserializeJson<MessageType>
//Do Calculations
let total = doCalculations //MessageReceived.ExchangeMessage.Amount 3.0
// send reply back to client
let message = encode <| total
message |> Socket.send responder
server ()