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.
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#).
A simple example is generating some XML, then adding some filters to eliminate some elements.
Here is my 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) -> (System.Int32.Parse(id) % 2).Equals(1)
/// Open filter which will return all people
let allFilter = fun (id:string, name:string) -> true
/// Generates a People XML Element.
let createPeople filter = new XElement(XName.Get("People"),
ppl |> List.filter(filter) |> 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 () -> System.Console.ReadKey() |> ignore
pauseKey()
My questions are: What things have I done well in this scenario? What parts could be done better?
I am really looking forward to some ideas and I am quite excited about becoming familiar with functional paradigms too! :)
Thanks in advance