Note that there are some explanatory texts on larger screens.

plurals
  1. POMy First F# program
    primarykey
    data
    text
    <p>I just finish writing my first F# program. Functionality wise the code works the way I wanted, but not sure if the code is efficient. I would much appreciate if someone could review the code for me and point out the areas where the code can be improved.</p> <p>Thanks Sudaly</p> <pre><code>open System open System.IO open System.IO.Pipes open System.Text open System.Collections.Generic open System.Runtime.Serialization [&lt;DataContract&gt;] type Quote = { [&lt;field: DataMember(Name="securityIdentifier") &gt;] RicCode:string [&lt;field: DataMember(Name="madeOn") &gt;] MadeOn:DateTime [&lt;field: DataMember(Name="closePrice") &gt;] Price:float } let m_cache = new Dictionary&lt;string, Quote&gt;() let ParseQuoteString (quoteString:string) = let data = Encoding.Unicode.GetBytes(quoteString) let stream = new MemoryStream() stream.Write(data, 0, data.Length); stream.Position &lt;- 0L let ser = Json.DataContractJsonSerializer(typeof&lt;Quote array&gt;) let results:Quote array = ser.ReadObject(stream) :?&gt; Quote array results let RefreshCache quoteList = m_cache.Clear() quoteList |&gt; Array.iter(fun result-&gt;m_cache.Add(result.RicCode, result)) let EstablishConnection() = let pipeServer = new NamedPipeServerStream("testpipe", PipeDirection.InOut, 4) let mutable sr = null printfn "[F#] NamedPipeServerStream thread created, Wait for a client to connect" pipeServer.WaitForConnection() printfn "[F#] Client connected." try // Stream for the request. sr &lt;- new StreamReader(pipeServer) with | _ as e -&gt; printfn "[F#]ERROR: %s" e.Message sr while true do let sr = EstablishConnection() // Read request from the stream. printfn "[F#] Ready to Receive data" sr.ReadLine() |&gt; ParseQuoteString |&gt; RefreshCache printfn "[F#]Quot Size, %d" m_cache.Count let quot = m_cache.["MSFT.OQ"] printfn "[F#]RIC: %s" quot.RicCode printfn "[F#]MadeOn: %s" (String.Format("{0:T}",quot.MadeOn)) printfn "[F#]Price: %f" quot.Price </code></pre>
    singulars
    1. This table or related slice is empty.
    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.
 

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