KEMBAR78
Exploring SharePoint with F# | PPTX
Exploring SharePoint with F#Talbott Crowell (MVP)@TalbottSharePoint Saturday New York CityJuly 30, 2011
Learn something new (exercise for the brain)Trend in functional programmingJava -> Clojure, ScalaErlangLINQ added to VB and C#Microsoft’s official (and only) functional programming languageWhy F#
Functional programming has been around a long timeNot newLong historyFunctional programming is safeA concern as we head toward manycore and cloud computingWhy another language?
1930’s: lambda calculus (roots)1956: IPL (Information Processing Language) “the first functional language1958: LISP “a functional flavored language”1962: APL (A Programming Language)1973: ML (Meta Language)1983: SML (Standard ML)1987: Caml (Categorical Abstract Machine Language ) and Haskell1996: OCaml (Objective Caml)Functional programming has been around a long time
Functional language developed by Microsoft ResearchBy Don Syme and his team, who productized GenericsBased on OCaml (influenced by C# and Haskell)History2002: F# language design started2005 January: F# 1.0.1 releases to publicNot a product.  Integration with VS2003Works in .NET 1.0 through .NET 2.0 beta, Mono2005 November: F# 1.1.5 with VS 2005 RTM support2009 October: VS2010 Beta 2, CTP for VS2008 & Non-Windows users2010: F# is “productized” and baked into VS 2010What is F#
Interactive Scripting Uses REPL (Read Evaluate Print Loop)Good for prototypingSuccinct = Less codeType InferenceStrongly typed, strictAutomatic generalization (generics for free)Few type annotations1st class functions (currying, lazy evaluations)Pattern matchingKey Characteristics of F#
Functional firstMutable keywordFunctions are first class valuesBlend of functional and imperativeObject oriented capabilitiesBuilt on .NET FrameworkPracticalLeverage existing codeWhat I like about F#
What is manycore?Lots of processors on one chipTens or hundredsIntel – Future (Task parallelism)NVIDIA GPU – Today (Data parallelism)500+ cores on chipGraphics, gaming, 3D renderingUse CUDA for financial or research computingProgram in C or C++
The Power Wall: CPU Clock SpeedManycore->Multicore->Single core->From Katherine Yelick’s “Multicore: Fallout of a Hardware Revolution”
Road to manycore1970 – 2005Single core on the “desktop” and laptop2006 – 2011Single core on the smartphone/tabletMulti core on the “desktop”Multi core in the cloud2012 – 2020Multi core on the smartphone/tablet2021Manycore probably will be common on many devices and computers
Multicore for Smartphones/TabletsAndroid 2.2 already supports multicoreNVIDIA dual core test with one core shut off1.5 to 1.6x faster with two coreshttp://bit.ly/nvidiadualcoreNVIDIA quad core on its waySmartphones by holiday season 2011Faster than 2 GHz notebook Core 2 Duo (T7200)http://bit.ly/eWMOsuQualcomm quad core SnapDragonDevices expected in 2013Intel announcing entry into Smartphone market
Declarative programming style	Easier to introduce parallelism into existing codeImmutability by defaultCan’t introduce race conditionsEasier to write lock-free codeFunctional Programming
Type inferenceExpressionsF# Basicslet x = 5let y = 5.0 let files = Directory.GetFiles(@"C:\images\original")let x = 5 * 5let y = 5.0 / 3.0let width = image.Width / 8
FunctionAnonymous functionsF# Functionslet sqr x = x * xsqr 5(fun x -> x * x) 5
The |> Combinator “Pipe Forward” ExampleF# Combinators x |> f          is the same as        f x  let sqr x = x * xsqr 5  5 |> sqr
The <| Combinator “Pipe Backward” ExampleF# Combinators f <| x          is the same as        f x  let sqr x = x * xsqr 5sqr <| 3 + 2       not same as    sqr 3 + 2
Similar to operator overloading ExampleSymbolic Functions let (operatorName) left right = <function>  open System.Text.RegularExpressions let (===) str regex = Regex.Match(str, regex).Success
Client Object Model
Adding References
For more info on Client Object ModelSee “Using the SharePoint Foundation 2010 Managed Client Object Model”http://msdn.microsoft.com/en-us/library/ee857094(office.14).aspx
Load References FSX ScriptOpen namespaceClient Object Model Assemblies#r @"..\ReferenceAssemblies\Microsoft.SharePoint.Client.dll"           #r @"..\ReferenceAssemblies\Microsoft.SharePoint.Client.Runtime.dll"open Microsoft.SharePoint.Client
Create SharePoint Client ContextPass CredentialsClient Context and Credentialslet ctx = new ClientContext("http://fsug.org")ctx.Credentials <- new NetworkCredential(	user, password, domain)
Helper function to Load and QueryRetrieve Site CollectionLoad and Query Contextlet load(ctx:ClientContext)(item:'a) =   ctx.Load(item)ctx.ExecuteQuery() let site = ctx.Site load ctx site
Site Collection (Site) and Site (Web)Site Collection and Sitelet site = ctx.Site load ctx site let web = site.RootWeb load ctx weblet title = web.Title
Use for loop to iterate through listsIterate through Lists load ctxweb.Lists for list in web.Lists do    print <| "List Title: " + list.Title
Query for list items using CAMLUse for loop to iterate through list itemsIterate through List Itemslet fsugMeetings = web.Lists.GetByTitle("FSUG Meetings")let query = new CamlQuery()query.ViewXml <- "<View><Query><OrderBy>...let listItems = fsugMeetings.GetItems(query)ctx.Load(fsugMeetings);ctx.Load(listItems);ctx.ExecuteQuery();for meeting in listItems do    print <| "Meeting: " + meeting.["Title"].ToString()
Use for loop to iterate through listsIterate through Lists load ctxweb.Lists for list in web.Lists do    print <| "List Title: " + list.Title
Demo
Future of F#Solution for the Data DelugeType ProvidersVideo by Keith Battocchi
Questions?
Thank YouReferences:http://TryFsharp.orgPlay with F# on browserTutorialLoad and save fileshttp://fsharp.netMore information
My InfoTalbott CrowellF# MVPhttp://fsug.orgNew England F# User Grouphttp://twitter.com/talbott  @talbott@BASPUGBoston Area SharePoint User Grouphttp://ThirdM.comThird Millennium, Inc.  Chief Architect

Exploring SharePoint with F#

  • 1.
    Exploring SharePoint withF#Talbott Crowell (MVP)@TalbottSharePoint Saturday New York CityJuly 30, 2011
  • 2.
    Learn something new(exercise for the brain)Trend in functional programmingJava -> Clojure, ScalaErlangLINQ added to VB and C#Microsoft’s official (and only) functional programming languageWhy F#
  • 3.
    Functional programming hasbeen around a long timeNot newLong historyFunctional programming is safeA concern as we head toward manycore and cloud computingWhy another language?
  • 4.
    1930’s: lambda calculus(roots)1956: IPL (Information Processing Language) “the first functional language1958: LISP “a functional flavored language”1962: APL (A Programming Language)1973: ML (Meta Language)1983: SML (Standard ML)1987: Caml (Categorical Abstract Machine Language ) and Haskell1996: OCaml (Objective Caml)Functional programming has been around a long time
  • 5.
    Functional language developedby Microsoft ResearchBy Don Syme and his team, who productized GenericsBased on OCaml (influenced by C# and Haskell)History2002: F# language design started2005 January: F# 1.0.1 releases to publicNot a product. Integration with VS2003Works in .NET 1.0 through .NET 2.0 beta, Mono2005 November: F# 1.1.5 with VS 2005 RTM support2009 October: VS2010 Beta 2, CTP for VS2008 & Non-Windows users2010: F# is “productized” and baked into VS 2010What is F#
  • 6.
    Interactive Scripting UsesREPL (Read Evaluate Print Loop)Good for prototypingSuccinct = Less codeType InferenceStrongly typed, strictAutomatic generalization (generics for free)Few type annotations1st class functions (currying, lazy evaluations)Pattern matchingKey Characteristics of F#
  • 7.
    Functional firstMutable keywordFunctionsare first class valuesBlend of functional and imperativeObject oriented capabilitiesBuilt on .NET FrameworkPracticalLeverage existing codeWhat I like about F#
  • 8.
    What is manycore?Lotsof processors on one chipTens or hundredsIntel – Future (Task parallelism)NVIDIA GPU – Today (Data parallelism)500+ cores on chipGraphics, gaming, 3D renderingUse CUDA for financial or research computingProgram in C or C++
  • 9.
    The Power Wall:CPU Clock SpeedManycore->Multicore->Single core->From Katherine Yelick’s “Multicore: Fallout of a Hardware Revolution”
  • 10.
    Road to manycore1970– 2005Single core on the “desktop” and laptop2006 – 2011Single core on the smartphone/tabletMulti core on the “desktop”Multi core in the cloud2012 – 2020Multi core on the smartphone/tablet2021Manycore probably will be common on many devices and computers
  • 11.
    Multicore for Smartphones/TabletsAndroid2.2 already supports multicoreNVIDIA dual core test with one core shut off1.5 to 1.6x faster with two coreshttp://bit.ly/nvidiadualcoreNVIDIA quad core on its waySmartphones by holiday season 2011Faster than 2 GHz notebook Core 2 Duo (T7200)http://bit.ly/eWMOsuQualcomm quad core SnapDragonDevices expected in 2013Intel announcing entry into Smartphone market
  • 12.
    Declarative programming style Easierto introduce parallelism into existing codeImmutability by defaultCan’t introduce race conditionsEasier to write lock-free codeFunctional Programming
  • 13.
    Type inferenceExpressionsF# Basicsletx = 5let y = 5.0 let files = Directory.GetFiles(@"C:\images\original")let x = 5 * 5let y = 5.0 / 3.0let width = image.Width / 8
  • 14.
    FunctionAnonymous functionsF# Functionsletsqr x = x * xsqr 5(fun x -> x * x) 5
  • 15.
    The |> Combinator“Pipe Forward” ExampleF# Combinators x |> f is the same as f x let sqr x = x * xsqr 5 5 |> sqr
  • 16.
    The <| Combinator“Pipe Backward” ExampleF# Combinators f <| x is the same as f x let sqr x = x * xsqr 5sqr <| 3 + 2 not same as sqr 3 + 2
  • 17.
    Similar to operatoroverloading ExampleSymbolic Functions let (operatorName) left right = <function> open System.Text.RegularExpressions let (===) str regex = Regex.Match(str, regex).Success
  • 18.
  • 20.
  • 21.
    For more infoon Client Object ModelSee “Using the SharePoint Foundation 2010 Managed Client Object Model”http://msdn.microsoft.com/en-us/library/ee857094(office.14).aspx
  • 22.
    Load References FSXScriptOpen namespaceClient Object Model Assemblies#r @"..\ReferenceAssemblies\Microsoft.SharePoint.Client.dll" #r @"..\ReferenceAssemblies\Microsoft.SharePoint.Client.Runtime.dll"open Microsoft.SharePoint.Client
  • 23.
    Create SharePoint ClientContextPass CredentialsClient Context and Credentialslet ctx = new ClientContext("http://fsug.org")ctx.Credentials <- new NetworkCredential( user, password, domain)
  • 24.
    Helper function toLoad and QueryRetrieve Site CollectionLoad and Query Contextlet load(ctx:ClientContext)(item:'a) = ctx.Load(item)ctx.ExecuteQuery() let site = ctx.Site load ctx site
  • 25.
    Site Collection (Site)and Site (Web)Site Collection and Sitelet site = ctx.Site load ctx site let web = site.RootWeb load ctx weblet title = web.Title
  • 26.
    Use for loopto iterate through listsIterate through Lists load ctxweb.Lists for list in web.Lists do print <| "List Title: " + list.Title
  • 27.
    Query for listitems using CAMLUse for loop to iterate through list itemsIterate through List Itemslet fsugMeetings = web.Lists.GetByTitle("FSUG Meetings")let query = new CamlQuery()query.ViewXml <- "<View><Query><OrderBy>...let listItems = fsugMeetings.GetItems(query)ctx.Load(fsugMeetings);ctx.Load(listItems);ctx.ExecuteQuery();for meeting in listItems do print <| "Meeting: " + meeting.["Title"].ToString()
  • 28.
    Use for loopto iterate through listsIterate through Lists load ctxweb.Lists for list in web.Lists do print <| "List Title: " + list.Title
  • 29.
  • 30.
    Future of F#Solutionfor the Data DelugeType ProvidersVideo by Keith Battocchi
  • 31.
  • 32.
    Thank YouReferences:http://TryFsharp.orgPlay withF# on browserTutorialLoad and save fileshttp://fsharp.netMore information
  • 33.
    My InfoTalbott CrowellF#MVPhttp://fsug.orgNew England F# User Grouphttp://twitter.com/talbott @talbott@BASPUGBoston Area SharePoint User Grouphttp://ThirdM.comThird Millennium, Inc. Chief Architect