SlideShare ist ein Scribd-Unternehmen logo
1 von 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

Weitere ähnliche Inhalte

Was ist angesagt?

Was ist angesagt? (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
 

Ähnlich wie 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
 

Ähnlich wie 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)
 

Mehr von 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
 

Mehr von 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
 

Kürzlich hochgeladen

Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilV3cube
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfhans926745
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessPixlogix Infotech
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
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
 
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
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobeapidays
 
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
 

Kürzlich hochgeladen (20)

Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
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...
 
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...
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
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
 

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