SlideShare una empresa de Scribd logo
1 de 31
F# Information Rich
Programming
Rodrigo Vidal
Visual F# MVP
What’s in this talk?
•   Intro to F#
•   Language features for solving real-world problems
•   F# Type Provider demos
•   Future directions
F# Tagline


 F# is a practical, functional-first language
       that lets you write simple code
         to solve complex problems
Created By
Motivation


        Ideas   Product



     Research   Reality
#inception



Lambda     LISP   ML   Ocaml   Haskell
Calculus                                 F#
F# 1.0
      Functional + Objects + .NET

 F# 2.0
     Functional + Objects + .NET +
Async + Parallel + Interactive + Scripting
12


                      C#, VB,
             10
                       Java
                                           LINQ       F#            Nirvana

              8



Usefulness    6                                                                            C#
                                                                                           Nirvana
              4                                                                            Haskell
                                                                                           LINQ
              2                                                    Haskell

              0
                  0        2           4          6           8          10          12


                                             Safety
    http://channel9.msdn.com/posts/Charles/Simon-Peyton-Jones-Towards-a-Programming-Language-Nirvana/
Immutability



       “Values are immutable by default”
Side Effects

  • Example: “The Butterfly Effect”


• A side effect
  •   Modifies some state
  •   Has observable interaction with calling functions
  •   Has observable interaction with the outside world
  •   Example: a function or method with no return value
Composing Functions
                   f(x)

f(x) = 3x+2
g(y) = 4y-1

     g(f(2)) = ?



                          g(x)
Simplicity
abstract class Command {

Simplicity                                 }
                                               public virtual void Execute();
                                                                                          C#

                                           abstract class RoverCommand : Command {
Functions as values                            protected Rover Rover { get; private set; }

                                               public RoverCommand(MarsRover rover) {
                                                   this.Rover = rover;
                                               }
 F#                                        }

                                           class BrakeCommand : RoverCommand {
type Command = Rover -> unit
                                               public BrakeCommand(Rover rover) : base(rover)
                                                  { }
let BrakeCommand =
                                               public override void Execute() {
   fun rover -> rover.Accelerate(-1.0)             Rover.Accelerate(-1.0);
                                               }
                                           }
let TurnLeftCommand =
                                           class TurnLeftCommand : RoverCommand {
   fun rover -> rover.Rotate(-5.0<degs>)       public TurnLeftCommand(Rover rover) : base(rover)
                                                   {}

                                               public override void Execute() {
                                                   Rover.Rotate(-5.0);
                                               }
                                           }
Simplicity
Functional data
     let swap (x, y) = (y, x)    Tuple<U,T> Swap<T,U>(Tuple<T,U> t)
F#                               {                                               C#
                                     return new Tuple<U,T>(t.Item2, t.Item1)
                                 }


     let rotations (x, y, z) =   ReadOnlyCollection<Tuple<T,T,T>> Rotations<T>
                                    (Tuple<T,T,T> t)
         [ (x, y, z);            {
           (z, x, y);              new ReadOnlyCollection<int>
                                    (new Tuple<T,T,T>[]
           (y, z, x) ]                { new Tuple<T,T,T>(t.Item1,t.Item2,t.Item3);
                                        new Tuple<T,T,T>(t.Item3,t.Item1,t.Item2);
                                        new Tuple<T,T,T>(t.Item2,t.Item3,t.Item1); });
                                 }

     let reduce f (x, y, z) =    int Reduce<T>(Func<T,int> f,Tuple<T,T,T> t)
                                 {
         f x + f y + f z             return f(t.Item1) + f(t.Item2) + f (t.Item3);
                                 }
F# is declarative
F# 3.0
Information Rich Programming
Two propositions
Proposition 1:
We live in an information society
Proposition 2:
Our languages are information sparse
A Big Problem
Challenges
• Impedance mismatch with statically-typed languages
• Need to manually integrate codegen tools with build
  process, source control, etc.
• No elegant way to handle schema change
• Loss of type information due to up-casts to Object, or
  even have to just parse strings
But…
• Data sources often have rich schemas and associated
  data definitions
• Static types should make your experience better, not
  worse!
Why this matters
Programming the web
F# Type Providers:
IntelliSense for data
Type provider
   IDE                   Compiler
IntelliSense for
                     Type-Check     Compile using
  Generated
                   Imported Types   Type Provider
     Types
Demo summary
• Can program against web-scale schematized data
  • code gen would never work here!
• Don’t have to wait for codegen or code to compile
• With typechecking!
  • Can detect schema change
• With great Visual Studio tooling!
Demo 3:
Web service with multiple data sources
What’s next for F#?
• Cloud, cloud cloud!
• Make F# programming on Azure even easier
• Can use F# computation expressions to add new syntax
  in a library
   • for example, cloud { … }
   • F# async and query expressions are not built-in
     syntax—they use computation expressions
Computation in the Cloud
Cloud Numerics
• Extensive library of numerical algorithms
  • Ranges from basic math to advanced statistics to linear algebra
• Supports distributed arrays and computation
• Can deploy to Azure when lots of compute resources are
  needed
F# Information Rich Programming

Más contenido relacionado

La actualidad más candente

Kotlin advanced - language reference for android developers
Kotlin advanced - language reference for android developersKotlin advanced - language reference for android developers
Kotlin advanced - language reference for android developersBartosz Kosarzycki
 
Kotlin For Android - Properties (part 4 of 7)
Kotlin For Android - Properties (part 4 of 7)Kotlin For Android - Properties (part 4 of 7)
Kotlin For Android - Properties (part 4 of 7)Gesh Markov
 
If You Think You Can Stay Away from Functional Programming, You Are Wrong
If You Think You Can Stay Away from Functional Programming, You Are WrongIf You Think You Can Stay Away from Functional Programming, You Are Wrong
If You Think You Can Stay Away from Functional Programming, You Are WrongMario Fusco
 
Introduction To Functional Programming
Introduction To Functional ProgrammingIntroduction To Functional Programming
Introduction To Functional Programmingnewmedio
 
[Codemotion 2015] patrones de diseño con java8
[Codemotion 2015] patrones de diseño con java8[Codemotion 2015] patrones de diseño con java8
[Codemotion 2015] patrones de diseño con java8Alonso Torres
 
The... Wonderful? World of Lambdas
The... Wonderful? World of LambdasThe... Wonderful? World of Lambdas
The... Wonderful? World of LambdasEsther Lozano
 
Functional Programming in Scala: Notes
Functional Programming in Scala: NotesFunctional Programming in Scala: Notes
Functional Programming in Scala: NotesRoberto Casadei
 
Intro to Functional Programming
Intro to Functional ProgrammingIntro to Functional Programming
Intro to Functional ProgrammingJordan Parmer
 
Practical Functional Programming Presentation by Bogdan Hodorog
Practical Functional Programming Presentation by Bogdan HodorogPractical Functional Programming Presentation by Bogdan Hodorog
Practical Functional Programming Presentation by Bogdan Hodorog3Pillar Global
 
Java 7, 8 & 9 - Moving the language forward
Java 7, 8 & 9 - Moving the language forwardJava 7, 8 & 9 - Moving the language forward
Java 7, 8 & 9 - Moving the language forwardMario Fusco
 
Kotlin as a Better Java
Kotlin as a Better JavaKotlin as a Better Java
Kotlin as a Better JavaGarth Gilmour
 
Introduction to functional programming using Ocaml
Introduction to functional programming using OcamlIntroduction to functional programming using Ocaml
Introduction to functional programming using Ocamlpramode_ce
 
The best of AltJava is Xtend
The best of AltJava is XtendThe best of AltJava is Xtend
The best of AltJava is Xtendtakezoe
 
STL ALGORITHMS
STL ALGORITHMSSTL ALGORITHMS
STL ALGORITHMSfawzmasood
 

La actualidad más candente (20)

Kotlin advanced - language reference for android developers
Kotlin advanced - language reference for android developersKotlin advanced - language reference for android developers
Kotlin advanced - language reference for android developers
 
Java 8 Workshop
Java 8 WorkshopJava 8 Workshop
Java 8 Workshop
 
Kotlin For Android - Properties (part 4 of 7)
Kotlin For Android - Properties (part 4 of 7)Kotlin For Android - Properties (part 4 of 7)
Kotlin For Android - Properties (part 4 of 7)
 
If You Think You Can Stay Away from Functional Programming, You Are Wrong
If You Think You Can Stay Away from Functional Programming, You Are WrongIf You Think You Can Stay Away from Functional Programming, You Are Wrong
If You Think You Can Stay Away from Functional Programming, You Are Wrong
 
Introduction To Functional Programming
Introduction To Functional ProgrammingIntroduction To Functional Programming
Introduction To Functional Programming
 
[Codemotion 2015] patrones de diseño con java8
[Codemotion 2015] patrones de diseño con java8[Codemotion 2015] patrones de diseño con java8
[Codemotion 2015] patrones de diseño con java8
 
The... Wonderful? World of Lambdas
The... Wonderful? World of LambdasThe... Wonderful? World of Lambdas
The... Wonderful? World of Lambdas
 
Functional Programming in Scala: Notes
Functional Programming in Scala: NotesFunctional Programming in Scala: Notes
Functional Programming in Scala: Notes
 
Functions
FunctionsFunctions
Functions
 
Intro to Functional Programming
Intro to Functional ProgrammingIntro to Functional Programming
Intro to Functional Programming
 
Practical Functional Programming Presentation by Bogdan Hodorog
Practical Functional Programming Presentation by Bogdan HodorogPractical Functional Programming Presentation by Bogdan Hodorog
Practical Functional Programming Presentation by Bogdan Hodorog
 
Java 7, 8 & 9 - Moving the language forward
Java 7, 8 & 9 - Moving the language forwardJava 7, 8 & 9 - Moving the language forward
Java 7, 8 & 9 - Moving the language forward
 
Kotlin as a Better Java
Kotlin as a Better JavaKotlin as a Better Java
Kotlin as a Better Java
 
MP in Clojure
MP in ClojureMP in Clojure
MP in Clojure
 
Introduction to functional programming using Ocaml
Introduction to functional programming using OcamlIntroduction to functional programming using Ocaml
Introduction to functional programming using Ocaml
 
Functional Programming in Java - Lessons Learned by GridGain
Functional Programming in Java - Lessons Learned by GridGainFunctional Programming in Java - Lessons Learned by GridGain
Functional Programming in Java - Lessons Learned by GridGain
 
Idiomatic C++
Idiomatic C++Idiomatic C++
Idiomatic C++
 
The best of AltJava is Xtend
The best of AltJava is XtendThe best of AltJava is Xtend
The best of AltJava is Xtend
 
Kotlin, why?
Kotlin, why?Kotlin, why?
Kotlin, why?
 
STL ALGORITHMS
STL ALGORITHMSSTL ALGORITHMS
STL ALGORITHMS
 

Destacado

PowerPoint: How to design it, How to use it
PowerPoint: How to design it, How to use itPowerPoint: How to design it, How to use it
PowerPoint: How to design it, How to use itBondSolon
 
Fugler a
Fugler aFugler a
Fugler aK3trinn
 
resume for photography
resume for photographyresume for photography
resume for photographyNguyễn Trung
 
STAR Interviews - Citadel Career Center
STAR Interviews - Citadel Career Center STAR Interviews - Citadel Career Center
STAR Interviews - Citadel Career Center Page Tisdale
 
Marketing Digital - Otimização para Sites de Busca
Marketing Digital - Otimização para Sites de BuscaMarketing Digital - Otimização para Sites de Busca
Marketing Digital - Otimização para Sites de BuscaLógica Digital
 
Soalan kbar dan kbat dst tahun 1
Soalan kbar dan kbat dst tahun 1Soalan kbar dan kbat dst tahun 1
Soalan kbar dan kbat dst tahun 1Yus Yusuf
 
Lab ndeg 3_-_ley_de_hooke_y_cambios_de_energia_potencial
Lab ndeg 3_-_ley_de_hooke_y_cambios_de_energia_potencialLab ndeg 3_-_ley_de_hooke_y_cambios_de_energia_potencial
Lab ndeg 3_-_ley_de_hooke_y_cambios_de_energia_potencialMargarita Castillo Soto
 

Destacado (15)

Primer ensayo-feym
Primer ensayo-feymPrimer ensayo-feym
Primer ensayo-feym
 
PowerPoint: How to design it, How to use it
PowerPoint: How to design it, How to use itPowerPoint: How to design it, How to use it
PowerPoint: How to design it, How to use it
 
Fugler a
Fugler aFugler a
Fugler a
 
Modelo de una base de datos 2
Modelo de una base de datos 2Modelo de una base de datos 2
Modelo de una base de datos 2
 
resume for photography
resume for photographyresume for photography
resume for photography
 
Clase n° 7
Clase n° 7Clase n° 7
Clase n° 7
 
Program schedule
Program scheduleProgram schedule
Program schedule
 
STAR Interviews - Citadel Career Center
STAR Interviews - Citadel Career Center STAR Interviews - Citadel Career Center
STAR Interviews - Citadel Career Center
 
Analisis translation widia
Analisis translation widiaAnalisis translation widia
Analisis translation widia
 
Checklist de usabilidade
Checklist de usabilidadeChecklist de usabilidade
Checklist de usabilidade
 
Marketing Digital - Otimização para Sites de Busca
Marketing Digital - Otimização para Sites de BuscaMarketing Digital - Otimização para Sites de Busca
Marketing Digital - Otimização para Sites de Busca
 
Secciones transversales
Secciones transversalesSecciones transversales
Secciones transversales
 
Soalan kbar dan kbat dst tahun 1
Soalan kbar dan kbat dst tahun 1Soalan kbar dan kbat dst tahun 1
Soalan kbar dan kbat dst tahun 1
 
Lab ndeg 3_-_ley_de_hooke_y_cambios_de_energia_potencial
Lab ndeg 3_-_ley_de_hooke_y_cambios_de_energia_potencialLab ndeg 3_-_ley_de_hooke_y_cambios_de_energia_potencial
Lab ndeg 3_-_ley_de_hooke_y_cambios_de_energia_potencial
 
Ergonomía ingenieril
Ergonomía ingenierilErgonomía ingenieril
Ergonomía ingenieril
 

Similar a F# Information Rich Programming

Rcpp: Seemless R and C++
Rcpp: Seemless R and C++Rcpp: Seemless R and C++
Rcpp: Seemless R and C++Romain Francois
 
Part 3-functions
Part 3-functionsPart 3-functions
Part 3-functionsankita44
 
Kotlin Bytecode Generation and Runtime Performance
Kotlin Bytecode Generation and Runtime PerformanceKotlin Bytecode Generation and Runtime Performance
Kotlin Bytecode Generation and Runtime Performanceintelliyole
 
User defined functions
User defined functionsUser defined functions
User defined functionsshubham_jangid
 
The Evolution of Async-Programming (SD 2.0, JavaScript)
The Evolution of Async-Programming (SD 2.0, JavaScript)The Evolution of Async-Programming (SD 2.0, JavaScript)
The Evolution of Async-Programming (SD 2.0, JavaScript)jeffz
 
How to start functional programming (in Scala): Day1
How to start functional programming (in Scala): Day1How to start functional programming (in Scala): Day1
How to start functional programming (in Scala): Day1Taisuke Oe
 
Coding in GO - GDG SL - NSBM
Coding in GO - GDG SL - NSBMCoding in GO - GDG SL - NSBM
Coding in GO - GDG SL - NSBMRaveen Perera
 
It's All About Morphisms
It's All About MorphismsIt's All About Morphisms
It's All About MorphismsUberto Barbini
 
Testing for share
Testing for share Testing for share
Testing for share Rajeev Mehta
 
Pydiomatic
PydiomaticPydiomatic
Pydiomaticrik0
 

Similar a F# Information Rich Programming (20)

Rcpp: Seemless R and C++
Rcpp: Seemless R and C++Rcpp: Seemless R and C++
Rcpp: Seemless R and C++
 
Part 3-functions
Part 3-functionsPart 3-functions
Part 3-functions
 
Functions12
Functions12Functions12
Functions12
 
Functions123
Functions123 Functions123
Functions123
 
Special topics in finance lecture 2
Special topics in finance   lecture 2Special topics in finance   lecture 2
Special topics in finance lecture 2
 
Fork Join (BeJUG 2012)
Fork Join (BeJUG 2012)Fork Join (BeJUG 2012)
Fork Join (BeJUG 2012)
 
Kotlin Bytecode Generation and Runtime Performance
Kotlin Bytecode Generation and Runtime PerformanceKotlin Bytecode Generation and Runtime Performance
Kotlin Bytecode Generation and Runtime Performance
 
User defined functions
User defined functionsUser defined functions
User defined functions
 
Xtext Webinar
Xtext WebinarXtext Webinar
Xtext Webinar
 
Hw09 Hadoop + Clojure
Hw09   Hadoop + ClojureHw09   Hadoop + Clojure
Hw09 Hadoop + Clojure
 
The Evolution of Async-Programming (SD 2.0, JavaScript)
The Evolution of Async-Programming (SD 2.0, JavaScript)The Evolution of Async-Programming (SD 2.0, JavaScript)
The Evolution of Async-Programming (SD 2.0, JavaScript)
 
How to start functional programming (in Scala): Day1
How to start functional programming (in Scala): Day1How to start functional programming (in Scala): Day1
How to start functional programming (in Scala): Day1
 
Hadoop + Clojure
Hadoop + ClojureHadoop + Clojure
Hadoop + Clojure
 
Coding in GO - GDG SL - NSBM
Coding in GO - GDG SL - NSBMCoding in GO - GDG SL - NSBM
Coding in GO - GDG SL - NSBM
 
It's All About Morphisms
It's All About MorphismsIt's All About Morphisms
It's All About Morphisms
 
Testing for share
Testing for share Testing for share
Testing for share
 
Monads in Swift
Monads in SwiftMonads in Swift
Monads in Swift
 
Xtext Webinar
Xtext WebinarXtext Webinar
Xtext Webinar
 
Pydiomatic
PydiomaticPydiomatic
Pydiomatic
 
Python idiomatico
Python idiomaticoPython idiomatico
Python idiomatico
 

Más de Rodrigo Vidal

DevDay BH 2011 Programação Funcional
DevDay BH 2011 Programação FuncionalDevDay BH 2011 Programação Funcional
DevDay BH 2011 Programação FuncionalRodrigo Vidal
 
WebCamps Software Testing
WebCamps Software TestingWebCamps Software Testing
WebCamps Software TestingRodrigo Vidal
 
Computacao em nuvem windows azure
Computacao em nuvem   windows azureComputacao em nuvem   windows azure
Computacao em nuvem windows azureRodrigo Vidal
 
F# Functional and MultiCore Programming
F# Functional and MultiCore Programming F# Functional and MultiCore Programming
F# Functional and MultiCore Programming Rodrigo Vidal
 
F# Ignite - DNAD2010
F# Ignite - DNAD2010F# Ignite - DNAD2010
F# Ignite - DNAD2010Rodrigo Vidal
 

Más de Rodrigo Vidal (8)

Fij
FijFij
Fij
 
Monadic Design
Monadic DesignMonadic Design
Monadic Design
 
C5, vb11, f3
C5, vb11, f3C5, vb11, f3
C5, vb11, f3
 
DevDay BH 2011 Programação Funcional
DevDay BH 2011 Programação FuncionalDevDay BH 2011 Programação Funcional
DevDay BH 2011 Programação Funcional
 
WebCamps Software Testing
WebCamps Software TestingWebCamps Software Testing
WebCamps Software Testing
 
Computacao em nuvem windows azure
Computacao em nuvem   windows azureComputacao em nuvem   windows azure
Computacao em nuvem windows azure
 
F# Functional and MultiCore Programming
F# Functional and MultiCore Programming F# Functional and MultiCore Programming
F# Functional and MultiCore Programming
 
F# Ignite - DNAD2010
F# Ignite - DNAD2010F# Ignite - DNAD2010
F# Ignite - DNAD2010
 

F# Information Rich Programming

  • 2. What’s in this talk? • Intro to F# • Language features for solving real-world problems • F# Type Provider demos • Future directions
  • 3. F# Tagline F# is a practical, functional-first language that lets you write simple code to solve complex problems
  • 5. Motivation Ideas Product Research Reality
  • 6. #inception Lambda LISP ML Ocaml Haskell Calculus F#
  • 7. F# 1.0 Functional + Objects + .NET F# 2.0 Functional + Objects + .NET + Async + Parallel + Interactive + Scripting
  • 8. 12 C#, VB, 10 Java LINQ F# Nirvana 8 Usefulness 6 C# Nirvana 4 Haskell LINQ 2 Haskell 0 0 2 4 6 8 10 12 Safety http://channel9.msdn.com/posts/Charles/Simon-Peyton-Jones-Towards-a-Programming-Language-Nirvana/
  • 9. Immutability “Values are immutable by default”
  • 10. Side Effects • Example: “The Butterfly Effect” • A side effect • Modifies some state • Has observable interaction with calling functions • Has observable interaction with the outside world • Example: a function or method with no return value
  • 11. Composing Functions f(x) f(x) = 3x+2 g(y) = 4y-1 g(f(2)) = ? g(x)
  • 13. abstract class Command { Simplicity } public virtual void Execute(); C# abstract class RoverCommand : Command { Functions as values protected Rover Rover { get; private set; } public RoverCommand(MarsRover rover) { this.Rover = rover; } F# } class BrakeCommand : RoverCommand { type Command = Rover -> unit public BrakeCommand(Rover rover) : base(rover) { } let BrakeCommand = public override void Execute() { fun rover -> rover.Accelerate(-1.0) Rover.Accelerate(-1.0); } } let TurnLeftCommand = class TurnLeftCommand : RoverCommand { fun rover -> rover.Rotate(-5.0<degs>) public TurnLeftCommand(Rover rover) : base(rover) {} public override void Execute() { Rover.Rotate(-5.0); } }
  • 14. Simplicity Functional data let swap (x, y) = (y, x) Tuple<U,T> Swap<T,U>(Tuple<T,U> t) F# { C# return new Tuple<U,T>(t.Item2, t.Item1) } let rotations (x, y, z) = ReadOnlyCollection<Tuple<T,T,T>> Rotations<T> (Tuple<T,T,T> t) [ (x, y, z); { (z, x, y); new ReadOnlyCollection<int> (new Tuple<T,T,T>[] (y, z, x) ] { new Tuple<T,T,T>(t.Item1,t.Item2,t.Item3); new Tuple<T,T,T>(t.Item3,t.Item1,t.Item2); new Tuple<T,T,T>(t.Item2,t.Item3,t.Item1); }); } let reduce f (x, y, z) = int Reduce<T>(Func<T,int> f,Tuple<T,T,T> t) { f x + f y + f z return f(t.Item1) + f(t.Item2) + f (t.Item3); }
  • 16. F# 3.0 Information Rich Programming
  • 18. Proposition 1: We live in an information society
  • 19. Proposition 2: Our languages are information sparse
  • 21. Challenges • Impedance mismatch with statically-typed languages • Need to manually integrate codegen tools with build process, source control, etc. • No elegant way to handle schema change • Loss of type information due to up-casts to Object, or even have to just parse strings
  • 22. But… • Data sources often have rich schemas and associated data definitions • Static types should make your experience better, not worse!
  • 25. Type provider IDE Compiler IntelliSense for Type-Check Compile using Generated Imported Types Type Provider Types
  • 26. Demo summary • Can program against web-scale schematized data • code gen would never work here! • Don’t have to wait for codegen or code to compile • With typechecking! • Can detect schema change • With great Visual Studio tooling!
  • 27. Demo 3: Web service with multiple data sources
  • 28. What’s next for F#? • Cloud, cloud cloud! • Make F# programming on Azure even easier • Can use F# computation expressions to add new syntax in a library • for example, cloud { … } • F# async and query expressions are not built-in syntax—they use computation expressions
  • 30. Cloud Numerics • Extensive library of numerical algorithms • Ranges from basic math to advanced statistics to linear algebra • Supports distributed arrays and computation • Can deploy to Azure when lots of compute resources are needed

Notas del editor

  1. have linq, have create way to manipulate data, but how do you get the schema?
  2. who here has used one of these apis?
  3. show how cloud numerics solves a problem“how would you do numerical analysis on large quantities of data?”(be interactive)- connect to problems they are already working on- “show how sausage is made” : what were we thinking in design?- type providers are linq on steroids