SlideShare uma empresa Scribd logo
1 de 41
F# and Silverlight Talbott Crowell F# User Group, April 5, 2010http://fsug.org
QuickIntro to F# Calculating Moving Average in F# Quick Intro to Silverlight Visualizing F# Using Silverlight Toolkit Agenda
Quick Intro to F#
Functional language developed by Microsoft Research 2002 language design started by Don Syme 2005 F# 1.0.1 public release (integration w/ VS2003) 2010 F# is “productized” and baked into VS2010 Multi-paradigm Functional/Imperative/OO/Language Oriented Key characteristics Succinct, Type Inference (strongly typed), 1st class functions What is F#
Type inferencing Strong typed Functions as values F# Intro b is a float let a = 5 let b = 6.0 let c = “7 feet” let d x = x * x let e = d b d is a function What data type is e?
The |> Combinator “Pipe Forward”  Example F# Combinators  x |> f       is the same as       f x   let sqr x = x * x sqr 5   5 |> sqr
Moving Average in F#
Start with a list of numbers Moving Average step 1 let testdata = [1.0 .. 10.0] testdata is a list of floats
Create windows of the series Moving Average step 2 Seq.windowed 4 testdata it is a sequence of float arrays
Average the values in each array Moving Average step 3 Array.average [|1.0; 2.0; 3.0; 4.0|]
Use Seq.map to calculate average of all arrays in the sequence Moving Average step 4 let windowedData = Seq.windowed period data Seq.map Array.averagewindowedData the first argument is the function to apply to each item in the sequence the second argument is the sequence
Use the pipe forward operator to put it together and omit the let Moving Average step 5 Seq.windowed period data  |> Seq.map Array.average
Put our algorithm into a function and test it Moving Average function let MovingAverage period data = Seq.windowed period data      |> Seq.map Array.average let testdata = [1.0 .. 10.0] let test = MovingAverage 4 testdata
Let’s generate some random data open System let GenerateData offset variance count =      let rnd = new Random()     let randomDouble variance = rnd.NextDouble() * variance     let indexes = Seq.ofList [0..(count-1)]     let genValuei =          let value = float i + offset + randomDouble variance         value     Seq.map genValue indexes let dataGenerator = GenerateData 50.0 100.0 200
Putting it together let data1 = List.ofSeqdataGenerator let data2 = List.ofSeq <| MovingAverage 10 data1
Time to visualize…
Quick Intro to Silverlight
What is Silverlight? Microsoft RIA plug-in for browsers 2007 Version 1.0 JavaScript based 2008 Version 2.0 .NET based 2009 Version 3.0 more controls, out of browser support (offline) 2010 Version 4.0 printing, COM, Multi-touch Runs on multiple browsers/OS IE, Safari, Firefox, Chrome / Win, MacOS, Linux* ,[object Object]
WPF/E (original name),[object Object]
Visual Studio 2008 Using Luke Hoban’s F# Silverlight templates Visual Studio 2010 RC Built-in F# Support for Silverlight in VS http://code.msdn.microsoft.com/fsharpsilverlight
Silverlight Toolkit http://silverlight.codeplex.com/ Silverlight SDK Silverlight 3 SDK Silverlight 4 SDK Beta Graphing Controls
Visualizing F# using Silverlight Toolkit
Use the “Silverlight Application” template in Visual Studio Creates Silverlight Application (produces XAP) Creates Web Application (hosts web site and XAP) Create a Silverlight Application
 Initial UserControl Notice XML Namespaces (need to add more) XAML
Add References
Add namespaces to XAML to support Silverlight Toolkit xmlns:controls="clr-namespace: System.Windows.Controls; assembly=System.Windows.Controls" xmlns:controlsToolkit="clr-namespace: System.Windows.Controls; assembly=System.Windows.Controls.Toolkit" xmlns:chartingToolkit="clr-namespace: System.Windows.Controls.DataVisualization.Charting; assembly=System.Windows.Controls.DataVisualization.Toolkit" xmlns:chartingPrimitivesToolkit="clr-namespace: System.Windows.Controls.DataVisualization.Charting.Primitives; assembly=System.Windows.Controls.DataVisualization.Toolkit"
Sample Series comes from Static Resource. Define Static Resource in App.xaml Add a chart to MainPage.xaml
add namespace add sample dataset Static Resource App.xaml
Similar to a Class Library project except it compiles with special options to target the Silverlight CLR Use file links to share F# files between Class Library and Silverlight Library Add Existing File Choose “Add As Link” from dropdown Create an F# Silverlight Library
SeriesDataPoint is a class (type) that has two members, Index and Value Used for series data Add Chart Helper type SeriesDataPoint(index, value) =     member this.Index with get() = index     member this.Value with get() = value
Used by XAML Designer to bind at design time Add Sample Data Set type SampleDataSet() =     static member SampleSeries1 =         let data = new ObjectCollection() data.Add(new SeriesDataPoint(0, 124.1)) data.Add(new SeriesDataPoint(1, 124.3)) data.Add(new SeriesDataPoint(2, 125.7)) data.Add(new SeriesDataPoint(3, 115.4)) data.Add(new SeriesDataPoint(4, 115.9)) data.Add(new SeriesDataPoint(5, 125.0)) data.Add(new SeriesDataPoint(6, 133.6)) data.Add(new SeriesDataPoint(7, 131.9)) data.Add(new SeriesDataPoint(8, 127.3)) data.Add(new SeriesDataPoint(9, 137.3))         data
Designer is now binding with F#
Code behind for MainPage.xaml Use constructor to wire up events Add code behind for MainPage public partial class MainPage : UserControl {    public MainPage()    { InitializeComponent(); SilverlightEvents.RegisterHandlers(this.LayoutRoot);    } }
Event handling code for application in F# SilverlightEvents in F#
Sample Button Click Event buttonGenerateSampleData.Click.Add(fun(_) ->    let data = GenerateDataPoints 125.0 10.0 10    let series = DataConverter.ConvertDataPointsToLineSeries        "Sample Series 3" data chart.Series.Add(series)    )
Slider Events - Mouse slider.MouseLeftButtonUp.Add(fun(_) -> model.UpdateSeries()) member internal this.UpdateSeries() = m_range <- (intslider.Value)    let movingAverage = MovingAveragem_rangem_data    let newSeries = this.GetMovingAverageSeriesmovingAverage chart.Series.[1] <- newSeries    ()
Slider Events – Value Changed slider.ValueChanged.Add(fun(callback) -> model.UpdateMovingAverage(callback)) member this.UpdateMovingAverage(args:RoutedPropertyChangedEventArgs<float>) =         let oldVal = intargs.OldValue         let newVal = intargs.NewValue         if oldVal = newVal then             () elif (Math.Abs(oldVal - newVal) > 4) then m_range <- newVal this.UpdateSeries()             ()         else m_range <- newVal             ()
Generate Data and Moving Average
Getting Started http://www.silverlight.net/getstarted/silverlight-4/ Tim Heuer’s Blog http://timheuer.com/blog/archive/2010/03/15/whats-new-in-silverlight-4-rc-mix10.aspx Silverlight 4 and Visual Studio 2010 RC
Bart Czernicki’s Silverlight Hack Blog http://www.silverlighthack.com/post/2009/11/04/Silverlight-3-and-FSharp-Support-in-Visual-Studio-2010.aspx Luke Hoban’s WebLog http://blogs.msdn.com/lukeh/archive/2009/06/26/f-in-silverlight.aspx support for F# in VS 2008 http://code.msdn.microsoft.com/fsharpsilverlight F# and Silverlight 2.0 http://jyliao.blogspot.com/2008/11/f-and-silverlight-20.html Other Helpful Links
http://fsug.org Thank you. Questions?F# and Silverlight Talbott Crowell ThirdM.com http://talbottc.spaces.live.com Twitter: @talbottand @fsug

Mais conteúdo relacionado

Mais procurados

Mais procurados (18)

Project of data structure
Project of data structureProject of data structure
Project of data structure
 
Stacks in Data Structure
Stacks in Data StructureStacks in Data Structure
Stacks in Data Structure
 
Data Structure (Stack)
Data Structure (Stack)Data Structure (Stack)
Data Structure (Stack)
 
Sql FUNCTIONS
Sql FUNCTIONSSql FUNCTIONS
Sql FUNCTIONS
 
Stack push pop
Stack push popStack push pop
Stack push pop
 
Stacks overview with its applications
Stacks overview with its applicationsStacks overview with its applications
Stacks overview with its applications
 
STACK ( LIFO STRUCTURE) - Data Structure
STACK ( LIFO STRUCTURE) - Data StructureSTACK ( LIFO STRUCTURE) - Data Structure
STACK ( LIFO STRUCTURE) - Data Structure
 
Controllers and context programming
Controllers and context programmingControllers and context programming
Controllers and context programming
 
React table tutorial use filter (part 2)
React table tutorial use filter (part 2)React table tutorial use filter (part 2)
React table tutorial use filter (part 2)
 
Introduction To Stack
Introduction To StackIntroduction To Stack
Introduction To Stack
 
Conversion of Infix To Postfix Expressions
Conversion of Infix To Postfix Expressions Conversion of Infix To Postfix Expressions
Conversion of Infix To Postfix Expressions
 
data structure, stack, stack data structure
data structure, stack, stack data structuredata structure, stack, stack data structure
data structure, stack, stack data structure
 
Stack and heap
Stack and heapStack and heap
Stack and heap
 
QuirksofR
QuirksofRQuirksofR
QuirksofR
 
The Ring programming language version 1.5.1 book - Part 20 of 180
The Ring programming language version 1.5.1 book - Part 20 of 180The Ring programming language version 1.5.1 book - Part 20 of 180
The Ring programming language version 1.5.1 book - Part 20 of 180
 
How to instantiate any view controller for free
How to instantiate any view controller for freeHow to instantiate any view controller for free
How to instantiate any view controller for free
 
Stacks
StacksStacks
Stacks
 
Stack data structure
Stack data structureStack data structure
Stack data structure
 

Semelhante a F# And Silverlight

Silverlight 2 for Developers - TechEd New Zealand 2008
Silverlight 2 for Developers - TechEd New Zealand 2008Silverlight 2 for Developers - TechEd New Zealand 2008
Silverlight 2 for Developers - TechEd New Zealand 2008Jonas Follesø
 
MSDN Presents: Visual Studio 2010, .NET 4, SharePoint 2010 for Developers
MSDN Presents: Visual Studio 2010, .NET 4, SharePoint 2010 for DevelopersMSDN Presents: Visual Studio 2010, .NET 4, SharePoint 2010 for Developers
MSDN Presents: Visual Studio 2010, .NET 4, SharePoint 2010 for DevelopersDave Bost
 
Daniel Egan Msdn Tech Days Oc Day2
Daniel Egan Msdn Tech Days Oc Day2Daniel Egan Msdn Tech Days Oc Day2
Daniel Egan Msdn Tech Days Oc Day2Daniel Egan
 
Rits Brown Bag - Salesforce Lightning
Rits Brown Bag - Salesforce LightningRits Brown Bag - Salesforce Lightning
Rits Brown Bag - Salesforce LightningRight IT Services
 
Pragmatic Parallels: Java and JavaScript
Pragmatic Parallels: Java and JavaScriptPragmatic Parallels: Java and JavaScript
Pragmatic Parallels: Java and JavaScriptdavejohnson
 
Visual Studio .NET2010
Visual Studio .NET2010Visual Studio .NET2010
Visual Studio .NET2010Satish Verma
 
Mike Taulty MIX10 Silverlight Frameworks and Patterns
Mike Taulty MIX10 Silverlight Frameworks and PatternsMike Taulty MIX10 Silverlight Frameworks and Patterns
Mike Taulty MIX10 Silverlight Frameworks and Patternsukdpe
 
Introduction To Google Android (Ft Rohan Bomle)
Introduction To Google Android (Ft Rohan Bomle)Introduction To Google Android (Ft Rohan Bomle)
Introduction To Google Android (Ft Rohan Bomle)Fafadia Tech
 
Windows Presentation Foundation
Windows Presentation FoundationWindows Presentation Foundation
Windows Presentation FoundationTran Ngoc Son
 
Core .NET Framework 4.0 Enhancements
Core .NET Framework 4.0 EnhancementsCore .NET Framework 4.0 Enhancements
Core .NET Framework 4.0 EnhancementsRobert MacLean
 
Android Tutorial
Android TutorialAndroid Tutorial
Android TutorialFun2Do Labs
 
Developing Android and iOS Apps With C#, .NET, Xamarin, Mono, and Windows Azure
Developing Android and iOS Apps With C#, .NET, Xamarin, Mono, and Windows AzureDeveloping Android and iOS Apps With C#, .NET, Xamarin, Mono, and Windows Azure
Developing Android and iOS Apps With C#, .NET, Xamarin, Mono, and Windows AzureRainer Stropek
 
Whidbey old
Whidbey old Whidbey old
Whidbey old grenaud
 
Exploring SharePoint with F#
Exploring SharePoint with F#Exploring SharePoint with F#
Exploring SharePoint with F#Talbott Crowell
 
SymfonyCon Berlin 2016 - Symfony Plugin for PhpStorm - 3 years later
SymfonyCon Berlin 2016 - Symfony Plugin for PhpStorm - 3 years laterSymfonyCon Berlin 2016 - Symfony Plugin for PhpStorm - 3 years later
SymfonyCon Berlin 2016 - Symfony Plugin for PhpStorm - 3 years laterHaehnchen
 
Programming with JavaFX
Programming with JavaFXProgramming with JavaFX
Programming with JavaFXFulvio Corno
 
J2ME Lwuit, Storage & Connections (Ft Prasanjit Dey)
J2ME Lwuit, Storage & Connections (Ft   Prasanjit Dey)J2ME Lwuit, Storage & Connections (Ft   Prasanjit Dey)
J2ME Lwuit, Storage & Connections (Ft Prasanjit Dey)Fafadia Tech
 

Semelhante a F# And Silverlight (20)

Silverlight 2 for Developers - TechEd New Zealand 2008
Silverlight 2 for Developers - TechEd New Zealand 2008Silverlight 2 for Developers - TechEd New Zealand 2008
Silverlight 2 for Developers - TechEd New Zealand 2008
 
MSDN Presents: Visual Studio 2010, .NET 4, SharePoint 2010 for Developers
MSDN Presents: Visual Studio 2010, .NET 4, SharePoint 2010 for DevelopersMSDN Presents: Visual Studio 2010, .NET 4, SharePoint 2010 for Developers
MSDN Presents: Visual Studio 2010, .NET 4, SharePoint 2010 for Developers
 
Test
TestTest
Test
 
Daniel Egan Msdn Tech Days Oc Day2
Daniel Egan Msdn Tech Days Oc Day2Daniel Egan Msdn Tech Days Oc Day2
Daniel Egan Msdn Tech Days Oc Day2
 
Rits Brown Bag - Salesforce Lightning
Rits Brown Bag - Salesforce LightningRits Brown Bag - Salesforce Lightning
Rits Brown Bag - Salesforce Lightning
 
Pragmatic Parallels: Java and JavaScript
Pragmatic Parallels: Java and JavaScriptPragmatic Parallels: Java and JavaScript
Pragmatic Parallels: Java and JavaScript
 
Visual Studio .NET2010
Visual Studio .NET2010Visual Studio .NET2010
Visual Studio .NET2010
 
Mike Taulty MIX10 Silverlight Frameworks and Patterns
Mike Taulty MIX10 Silverlight Frameworks and PatternsMike Taulty MIX10 Silverlight Frameworks and Patterns
Mike Taulty MIX10 Silverlight Frameworks and Patterns
 
Introduction To Google Android (Ft Rohan Bomle)
Introduction To Google Android (Ft Rohan Bomle)Introduction To Google Android (Ft Rohan Bomle)
Introduction To Google Android (Ft Rohan Bomle)
 
Jsf intro
Jsf introJsf intro
Jsf intro
 
Windows Presentation Foundation
Windows Presentation FoundationWindows Presentation Foundation
Windows Presentation Foundation
 
Core .NET Framework 4.0 Enhancements
Core .NET Framework 4.0 EnhancementsCore .NET Framework 4.0 Enhancements
Core .NET Framework 4.0 Enhancements
 
Android Tutorial
Android TutorialAndroid Tutorial
Android Tutorial
 
Developing Android and iOS Apps With C#, .NET, Xamarin, Mono, and Windows Azure
Developing Android and iOS Apps With C#, .NET, Xamarin, Mono, and Windows AzureDeveloping Android and iOS Apps With C#, .NET, Xamarin, Mono, and Windows Azure
Developing Android and iOS Apps With C#, .NET, Xamarin, Mono, and Windows Azure
 
Whidbey old
Whidbey old Whidbey old
Whidbey old
 
Exploring SharePoint with F#
Exploring SharePoint with F#Exploring SharePoint with F#
Exploring SharePoint with F#
 
SymfonyCon Berlin 2016 - Symfony Plugin for PhpStorm - 3 years later
SymfonyCon Berlin 2016 - Symfony Plugin for PhpStorm - 3 years laterSymfonyCon Berlin 2016 - Symfony Plugin for PhpStorm - 3 years later
SymfonyCon Berlin 2016 - Symfony Plugin for PhpStorm - 3 years later
 
Griffon Presentation
Griffon PresentationGriffon Presentation
Griffon Presentation
 
Programming with JavaFX
Programming with JavaFXProgramming with JavaFX
Programming with JavaFX
 
J2ME Lwuit, Storage & Connections (Ft Prasanjit Dey)
J2ME Lwuit, Storage & Connections (Ft   Prasanjit Dey)J2ME Lwuit, Storage & Connections (Ft   Prasanjit Dey)
J2ME Lwuit, Storage & Connections (Ft Prasanjit Dey)
 

Mais de Talbott Crowell

Top 3 Mistakes when Building
Top 3 Mistakes when BuildingTop 3 Mistakes when Building
Top 3 Mistakes when BuildingTalbott Crowell
 
Building high performance and scalable share point applications
Building high performance and scalable share point applicationsBuilding high performance and scalable share point applications
Building high performance and scalable share point applicationsTalbott Crowell
 
Road to the Cloud - Extending your reach with SharePoint and Office 365
Road to the Cloud - Extending your reach with SharePoint and Office 365Road to the Cloud - Extending your reach with SharePoint and Office 365
Road to the Cloud - Extending your reach with SharePoint and Office 365Talbott Crowell
 
Custom Development for SharePoint
Custom Development for SharePointCustom Development for SharePoint
Custom Development for SharePointTalbott Crowell
 
Custom Development in SharePoint – What are my options now?
Custom Development in SharePoint – What are my options now?Custom Development in SharePoint – What are my options now?
Custom Development in SharePoint – What are my options now?Talbott Crowell
 
Developing a Provider Hosted SharePoint app
Developing a Provider Hosted SharePoint appDeveloping a Provider Hosted SharePoint app
Developing a Provider Hosted SharePoint appTalbott Crowell
 
Developing a provider hosted share point app
Developing a provider hosted share point appDeveloping a provider hosted share point app
Developing a provider hosted share point appTalbott Crowell
 
PowerShell and SharePoint @spsnyc July 2012
PowerShell and SharePoint @spsnyc July 2012PowerShell and SharePoint @spsnyc July 2012
PowerShell and SharePoint @spsnyc July 2012Talbott Crowell
 
PowerShell and SharePoint
PowerShell and SharePointPowerShell and SharePoint
PowerShell and SharePointTalbott Crowell
 
Automating PowerShell with SharePoint
Automating PowerShell with SharePointAutomating PowerShell with SharePoint
Automating PowerShell with SharePointTalbott Crowell
 
SharePoint Saturday Boston 2010
SharePoint Saturday Boston 2010SharePoint Saturday Boston 2010
SharePoint Saturday Boston 2010Talbott Crowell
 
Automating SQL Server Database Creation for SharePoint
Automating SQL Server Database Creation for SharePointAutomating SQL Server Database Creation for SharePoint
Automating SQL Server Database Creation for SharePointTalbott Crowell
 
Architecting Solutions for the Manycore Future
Architecting Solutions for the Manycore FutureArchitecting Solutions for the Manycore Future
Architecting Solutions for the Manycore FutureTalbott Crowell
 

Mais de Talbott Crowell (17)

Top 7 mistakes
Top 7 mistakesTop 7 mistakes
Top 7 mistakes
 
Top 3 Mistakes when Building
Top 3 Mistakes when BuildingTop 3 Mistakes when Building
Top 3 Mistakes when Building
 
Building high performance and scalable share point applications
Building high performance and scalable share point applicationsBuilding high performance and scalable share point applications
Building high performance and scalable share point applications
 
Road to the Cloud - Extending your reach with SharePoint and Office 365
Road to the Cloud - Extending your reach with SharePoint and Office 365Road to the Cloud - Extending your reach with SharePoint and Office 365
Road to the Cloud - Extending your reach with SharePoint and Office 365
 
Custom Development for SharePoint
Custom Development for SharePointCustom Development for SharePoint
Custom Development for SharePoint
 
Custom Development in SharePoint – What are my options now?
Custom Development in SharePoint – What are my options now?Custom Development in SharePoint – What are my options now?
Custom Development in SharePoint – What are my options now?
 
Developing a Provider Hosted SharePoint app
Developing a Provider Hosted SharePoint appDeveloping a Provider Hosted SharePoint app
Developing a Provider Hosted SharePoint app
 
Developing a provider hosted share point app
Developing a provider hosted share point appDeveloping a provider hosted share point app
Developing a provider hosted share point app
 
Introduction to F# 3.0
Introduction to F# 3.0Introduction to F# 3.0
Introduction to F# 3.0
 
PowerShell and SharePoint @spsnyc July 2012
PowerShell and SharePoint @spsnyc July 2012PowerShell and SharePoint @spsnyc July 2012
PowerShell and SharePoint @spsnyc July 2012
 
PowerShell and SharePoint
PowerShell and SharePointPowerShell and SharePoint
PowerShell and SharePoint
 
Welcome to windows 8
Welcome to windows 8Welcome to windows 8
Welcome to windows 8
 
Automating PowerShell with SharePoint
Automating PowerShell with SharePointAutomating PowerShell with SharePoint
Automating PowerShell with SharePoint
 
SharePoint Saturday Boston 2010
SharePoint Saturday Boston 2010SharePoint Saturday Boston 2010
SharePoint Saturday Boston 2010
 
Automating SQL Server Database Creation for SharePoint
Automating SQL Server Database Creation for SharePointAutomating SQL Server Database Creation for SharePoint
Automating SQL Server Database Creation for SharePoint
 
Introduction to F#
Introduction to F#Introduction to F#
Introduction to F#
 
Architecting Solutions for the Manycore Future
Architecting Solutions for the Manycore FutureArchitecting Solutions for the Manycore Future
Architecting Solutions for the Manycore Future
 

Último

TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsNanddeep Nachan
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MIND CTI
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdfSandro Moreira
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...apidays
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native ApplicationsWSO2
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...DianaGray10
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Jeffrey Haguewood
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodJuan lago vázquez
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingEdi Saputra
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Angeliki Cooney
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...apidays
 

Último (20)

TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 

F# And Silverlight

  • 1. F# and Silverlight Talbott Crowell F# User Group, April 5, 2010http://fsug.org
  • 2. QuickIntro to F# Calculating Moving Average in F# Quick Intro to Silverlight Visualizing F# Using Silverlight Toolkit Agenda
  • 4. Functional language developed by Microsoft Research 2002 language design started by Don Syme 2005 F# 1.0.1 public release (integration w/ VS2003) 2010 F# is “productized” and baked into VS2010 Multi-paradigm Functional/Imperative/OO/Language Oriented Key characteristics Succinct, Type Inference (strongly typed), 1st class functions What is F#
  • 5. Type inferencing Strong typed Functions as values F# Intro b is a float let a = 5 let b = 6.0 let c = “7 feet” let d x = x * x let e = d b d is a function What data type is e?
  • 6. The |> Combinator “Pipe Forward” Example F# Combinators x |> f is the same as f x let sqr x = x * x sqr 5 5 |> sqr
  • 8. Start with a list of numbers Moving Average step 1 let testdata = [1.0 .. 10.0] testdata is a list of floats
  • 9. Create windows of the series Moving Average step 2 Seq.windowed 4 testdata it is a sequence of float arrays
  • 10. Average the values in each array Moving Average step 3 Array.average [|1.0; 2.0; 3.0; 4.0|]
  • 11. Use Seq.map to calculate average of all arrays in the sequence Moving Average step 4 let windowedData = Seq.windowed period data Seq.map Array.averagewindowedData the first argument is the function to apply to each item in the sequence the second argument is the sequence
  • 12. Use the pipe forward operator to put it together and omit the let Moving Average step 5 Seq.windowed period data |> Seq.map Array.average
  • 13. Put our algorithm into a function and test it Moving Average function let MovingAverage period data = Seq.windowed period data |> Seq.map Array.average let testdata = [1.0 .. 10.0] let test = MovingAverage 4 testdata
  • 14. Let’s generate some random data open System let GenerateData offset variance count = let rnd = new Random() let randomDouble variance = rnd.NextDouble() * variance let indexes = Seq.ofList [0..(count-1)] let genValuei = let value = float i + offset + randomDouble variance value Seq.map genValue indexes let dataGenerator = GenerateData 50.0 100.0 200
  • 15. Putting it together let data1 = List.ofSeqdataGenerator let data2 = List.ofSeq <| MovingAverage 10 data1
  • 17. Quick Intro to Silverlight
  • 18.
  • 19.
  • 20. Visual Studio 2008 Using Luke Hoban’s F# Silverlight templates Visual Studio 2010 RC Built-in F# Support for Silverlight in VS http://code.msdn.microsoft.com/fsharpsilverlight
  • 21. Silverlight Toolkit http://silverlight.codeplex.com/ Silverlight SDK Silverlight 3 SDK Silverlight 4 SDK Beta Graphing Controls
  • 22. Visualizing F# using Silverlight Toolkit
  • 23. Use the “Silverlight Application” template in Visual Studio Creates Silverlight Application (produces XAP) Creates Web Application (hosts web site and XAP) Create a Silverlight Application
  • 24. Initial UserControl Notice XML Namespaces (need to add more) XAML
  • 26. Add namespaces to XAML to support Silverlight Toolkit xmlns:controls="clr-namespace: System.Windows.Controls; assembly=System.Windows.Controls" xmlns:controlsToolkit="clr-namespace: System.Windows.Controls; assembly=System.Windows.Controls.Toolkit" xmlns:chartingToolkit="clr-namespace: System.Windows.Controls.DataVisualization.Charting; assembly=System.Windows.Controls.DataVisualization.Toolkit" xmlns:chartingPrimitivesToolkit="clr-namespace: System.Windows.Controls.DataVisualization.Charting.Primitives; assembly=System.Windows.Controls.DataVisualization.Toolkit"
  • 27. Sample Series comes from Static Resource. Define Static Resource in App.xaml Add a chart to MainPage.xaml
  • 28. add namespace add sample dataset Static Resource App.xaml
  • 29. Similar to a Class Library project except it compiles with special options to target the Silverlight CLR Use file links to share F# files between Class Library and Silverlight Library Add Existing File Choose “Add As Link” from dropdown Create an F# Silverlight Library
  • 30. SeriesDataPoint is a class (type) that has two members, Index and Value Used for series data Add Chart Helper type SeriesDataPoint(index, value) = member this.Index with get() = index member this.Value with get() = value
  • 31. Used by XAML Designer to bind at design time Add Sample Data Set type SampleDataSet() = static member SampleSeries1 = let data = new ObjectCollection() data.Add(new SeriesDataPoint(0, 124.1)) data.Add(new SeriesDataPoint(1, 124.3)) data.Add(new SeriesDataPoint(2, 125.7)) data.Add(new SeriesDataPoint(3, 115.4)) data.Add(new SeriesDataPoint(4, 115.9)) data.Add(new SeriesDataPoint(5, 125.0)) data.Add(new SeriesDataPoint(6, 133.6)) data.Add(new SeriesDataPoint(7, 131.9)) data.Add(new SeriesDataPoint(8, 127.3)) data.Add(new SeriesDataPoint(9, 137.3)) data
  • 32. Designer is now binding with F#
  • 33. Code behind for MainPage.xaml Use constructor to wire up events Add code behind for MainPage public partial class MainPage : UserControl { public MainPage() { InitializeComponent(); SilverlightEvents.RegisterHandlers(this.LayoutRoot); } }
  • 34. Event handling code for application in F# SilverlightEvents in F#
  • 35. Sample Button Click Event buttonGenerateSampleData.Click.Add(fun(_) -> let data = GenerateDataPoints 125.0 10.0 10 let series = DataConverter.ConvertDataPointsToLineSeries "Sample Series 3" data chart.Series.Add(series) )
  • 36. Slider Events - Mouse slider.MouseLeftButtonUp.Add(fun(_) -> model.UpdateSeries()) member internal this.UpdateSeries() = m_range <- (intslider.Value) let movingAverage = MovingAveragem_rangem_data let newSeries = this.GetMovingAverageSeriesmovingAverage chart.Series.[1] <- newSeries ()
  • 37. Slider Events – Value Changed slider.ValueChanged.Add(fun(callback) -> model.UpdateMovingAverage(callback)) member this.UpdateMovingAverage(args:RoutedPropertyChangedEventArgs<float>) = let oldVal = intargs.OldValue let newVal = intargs.NewValue if oldVal = newVal then () elif (Math.Abs(oldVal - newVal) > 4) then m_range <- newVal this.UpdateSeries() () else m_range <- newVal ()
  • 38. Generate Data and Moving Average
  • 39. Getting Started http://www.silverlight.net/getstarted/silverlight-4/ Tim Heuer’s Blog http://timheuer.com/blog/archive/2010/03/15/whats-new-in-silverlight-4-rc-mix10.aspx Silverlight 4 and Visual Studio 2010 RC
  • 40. Bart Czernicki’s Silverlight Hack Blog http://www.silverlighthack.com/post/2009/11/04/Silverlight-3-and-FSharp-Support-in-Visual-Studio-2010.aspx Luke Hoban’s WebLog http://blogs.msdn.com/lukeh/archive/2009/06/26/f-in-silverlight.aspx support for F# in VS 2008 http://code.msdn.microsoft.com/fsharpsilverlight F# and Silverlight 2.0 http://jyliao.blogspot.com/2008/11/f-and-silverlight-20.html Other Helpful Links
  • 41. http://fsug.org Thank you. Questions?F# and Silverlight Talbott Crowell ThirdM.com http://talbottc.spaces.live.com Twitter: @talbottand @fsug