Note that there are some explanatory texts on larger screens.

plurals
  1. POCoding Practice for F#
    primarykey
    data
    text
    <p>I have been dabbling with F# in Visual Studio 2010. I am a developer with more code/architecture design experience in object-oriented languages such as C# and Java. </p> <p>To expand my skill set and help make better decisions I am trying different languages to do different things. In particular get the hang of coding "correctly" using functional languages (in this case F#).</p> <p>A simple example is generating some XML, then adding some filters to eliminate some elements.</p> <p>Here is my code:</p> <pre><code>open System open System.Xml.Linq let ppl:(string * string) list = [ ("1", "Jerry"); ("2", "Max"); ("3", "Andrew"); ] /// Generates a Person XML Element, given a tuple. let createPerson (id:string, name:string) = new XElement(XName.Get("Person"), new XAttribute(XName.Get("ID"), id), new XElement(XName.Get("Name"), name) ) /// Filter People by having odd ID's let oddFilter = fun (id:string, name:string) -&gt; (System.Int32.Parse(id) % 2).Equals(1) /// Open filter which will return all people let allFilter = fun (id:string, name:string) -&gt; true /// Generates a People XML Element. let createPeople filter = new XElement(XName.Get("People"), ppl |&gt; List.filter(filter) |&gt; List.map createPerson ) /// First XML Object let XmlA = createPeople oddFilter /// Second XML Object let XmlB = createPeople allFilter printf "%A\n\n%A" XmlA XmlB /// Waits for a keypress let pauseKey = fun () -&gt; System.Console.ReadKey() |&gt; ignore pauseKey() </code></pre> <p>My questions are: What things have I done well in this scenario? What parts could be done better? </p> <p>I am really looking forward to some ideas and I am quite excited about becoming familiar with functional paradigms too! :)</p> <p>Thanks in advance</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.
 

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