SlideShare a Scribd company logo
1 of 22
A language you can brag about
Functional programming

     The new hotness
    Next “big” .NET language

     CTP this summer
OCaml offspring

    Created by MS Research

    Mixed mode language

     Functional
     OO
     Imperative (if you must)
    Statically typed

Yay! Type inference
                 
let x = 7
                     ...also, immutable
                 
let s = quot;kurtquot;
let pi = 3.142       So, really just “values”
                 
let l = ['a';'b';'c';]
// char list or list<char>
                                 Singly linked list
                             
                                 Still immutable!
                             
let digits = [0..9]
// int list
IEnumerable<T>
                    
let s = {1..10}
                        Useful for computing
                    
// seq[1;2;3;...]
                        unbounded lists
let me = (quot;kurtquot;, 6.0)
                             Typed groups of values
                         
// string * float
                             Can “hold” anything
                         
let point3d = (0,0,0)        Basically awesome
                         
// int * int * int
let add x y = x + y
                           Like any other value
                       
// int -> int -> int
                           More type inference
                       
let eight = add 3 5        Returns last expression
                       
// eight = 8
Look ma! Generics!
                         
let group x y = (x,y)
// 'a -> 'b -> 'a * 'b        Auto-generalization
let rec fib n =
    if n < 2 then
        n
                              Explicitly recursive
                          
    else
                              Tail recursion
                          
        (fib (n - 1)) +
        (fib (n - 2))
type name = string
type number = int
type date = System.DateTime
type meeting =
    | Personal of name   * date
    | Phone    of number * date

let review = Personal(quot;Jasminequot;,System.DateTime.Now)
let call = Phone(8675309, System.DateTime.Now)
let what_to_do (m : meeting) =
    match m with
    | Personal(name,date) ->
        printfn quot;Meeting with %s at %Aquot; name date
    | Phone(phone, date) ->
        printfn quot;Call %A at %Aquot; phone date
Functions are basic units of a program

    We can mix them up in interesting ways

     Less OO design patterns!
    “Cheap” functions are good

     Code is more expressive
let add3 = add 3
let add x y = x + y
                       // int -> int
// int -> int -> int
let even x = x % 2 = 0
                            // int -> bool
                            let numbers = [1..20]
let (|>) x f = f x          // int list
                            let evens =
// 'a -> ('a -> 'b) -> 'b
                                numbers |>
                                    List.filter even
                            // int list
List.fold_left
                           // ('b -> 'a -> 'b) ->
List.map
                           // 'b ->
// ('a -> 'b) ->
                           // 'a list ->
// 'a list ->
                           // 'b
// 'b list
                           [1..10] |> List.fold_left
[1..10] |> List.map add3
                             (fun acc x -> acc + x) 0
// [4;5;6;..;13]
                           // 55
2520 is the smallest number that can be

    divided by each of the numbers from 1 to 10
    without any remainder.
    What is the smallest number that is evenly

    divisible by all of the numbers from 1 to 20?
                                      - Project Euler
                                   projecteuler.net
“Mutable” keyword

     For real variables
    There are imperative loops

     Try not to use it too much
F# can be OO

     Classes
     Interfaces
     Inheritance
    Cross language work

     “Hide” implementation
type OrderLine(n:string, q:int, p:float) =
    let mutable currName = n
    let mutable currQuantity = q
    let mutable currPrice = p
    new (name, price) = OrderLine(name, 1, price)
    member x.Name
        with get() = currName
        and set name = currName <- name
    member x.SubTotal with get() =
        (Float.of_int quantity) * price
    member x.OneMore() =
        currQuantity <- currQuantity + 1
        currQuantity
Why functional programming?

     Easy to build incrementally
     Simplified testing
     Concurrency!
    Imperative can be good too

     At times, it’s wickedly fast
     It’s what we know
F# Presentation

More Related Content

What's hot

Prefix, Infix and Post-fix Notations
Prefix, Infix and Post-fix NotationsPrefix, Infix and Post-fix Notations
Prefix, Infix and Post-fix NotationsAfaq Mansoor Khan
 
Functional Error Handling with Cats
Functional Error Handling with CatsFunctional Error Handling with Cats
Functional Error Handling with CatsMark Canlas
 
PHP Form Validation Technique
PHP Form Validation TechniquePHP Form Validation Technique
PHP Form Validation TechniqueMorshedul Arefin
 
Two-dimensional array in java
Two-dimensional array in javaTwo-dimensional array in java
Two-dimensional array in javaTalha mahmood
 
PHP - DataType,Variable,Constant,Operators,Array,Include and require
PHP - DataType,Variable,Constant,Operators,Array,Include and requirePHP - DataType,Variable,Constant,Operators,Array,Include and require
PHP - DataType,Variable,Constant,Operators,Array,Include and requireTheCreativedev Blog
 
Regular expressions in Python
Regular expressions in PythonRegular expressions in Python
Regular expressions in PythonSujith Kumar
 
Infix to Postfix Conversion Using Stack
Infix to Postfix Conversion Using StackInfix to Postfix Conversion Using Stack
Infix to Postfix Conversion Using StackSoumen Santra
 
Sorting Techniques
Sorting TechniquesSorting Techniques
Sorting TechniquesRafay Farooq
 
Evaluation of postfix expression
Evaluation of postfix expressionEvaluation of postfix expression
Evaluation of postfix expressionAkhil Ahuja
 
Conditionalstatement
ConditionalstatementConditionalstatement
ConditionalstatementRaginiJain21
 
C++: Constructor, Copy Constructor and Assignment operator
C++: Constructor, Copy Constructor and Assignment operatorC++: Constructor, Copy Constructor and Assignment operator
C++: Constructor, Copy Constructor and Assignment operatorJussi Pohjolainen
 

What's hot (20)

Prefix, Infix and Post-fix Notations
Prefix, Infix and Post-fix NotationsPrefix, Infix and Post-fix Notations
Prefix, Infix and Post-fix Notations
 
Functional Error Handling with Cats
Functional Error Handling with CatsFunctional Error Handling with Cats
Functional Error Handling with Cats
 
PHP Form Validation Technique
PHP Form Validation TechniquePHP Form Validation Technique
PHP Form Validation Technique
 
C Programming Unit-4
C Programming Unit-4C Programming Unit-4
C Programming Unit-4
 
Two-dimensional array in java
Two-dimensional array in javaTwo-dimensional array in java
Two-dimensional array in java
 
queues
queuesqueues
queues
 
C# Arrays
C# ArraysC# Arrays
C# Arrays
 
PHP - DataType,Variable,Constant,Operators,Array,Include and require
PHP - DataType,Variable,Constant,Operators,Array,Include and requirePHP - DataType,Variable,Constant,Operators,Array,Include and require
PHP - DataType,Variable,Constant,Operators,Array,Include and require
 
Matlab1
Matlab1Matlab1
Matlab1
 
Regular expressions in Python
Regular expressions in PythonRegular expressions in Python
Regular expressions in Python
 
Python OOPs
Python OOPsPython OOPs
Python OOPs
 
Infix to Postfix Conversion Using Stack
Infix to Postfix Conversion Using StackInfix to Postfix Conversion Using Stack
Infix to Postfix Conversion Using Stack
 
Python oop third class
Python oop   third classPython oop   third class
Python oop third class
 
Sorting Techniques
Sorting TechniquesSorting Techniques
Sorting Techniques
 
Array in c#
Array in c#Array in c#
Array in c#
 
Evaluation of postfix expression
Evaluation of postfix expressionEvaluation of postfix expression
Evaluation of postfix expression
 
Conditionalstatement
ConditionalstatementConditionalstatement
Conditionalstatement
 
C# Strings
C# StringsC# Strings
C# Strings
 
Arrays in c
Arrays in cArrays in c
Arrays in c
 
C++: Constructor, Copy Constructor and Assignment operator
C++: Constructor, Copy Constructor and Assignment operatorC++: Constructor, Copy Constructor and Assignment operator
C++: Constructor, Copy Constructor and Assignment operator
 

Viewers also liked

Sequential file programming patterns and performance with .net
Sequential  file programming patterns and performance with .netSequential  file programming patterns and performance with .net
Sequential file programming patterns and performance with .netMichael Pavlovsky
 
Moq Presentation
Moq PresentationMoq Presentation
Moq PresentationLynxStar
 
Mock driven development using .NET
Mock driven development using .NETMock driven development using .NET
Mock driven development using .NETPuneet Ghanshani
 
Domain Driven Design with the F# type System -- NDC London 2013
Domain Driven Design with the F# type System -- NDC London 2013Domain Driven Design with the F# type System -- NDC London 2013
Domain Driven Design with the F# type System -- NDC London 2013Scott Wlaschin
 
Functional Programming in C# and F#
Functional Programming in C# and F#Functional Programming in C# and F#
Functional Programming in C# and F#Alfonso Garcia-Caro
 
Principles and patterns for test driven development
Principles and patterns for test driven developmentPrinciples and patterns for test driven development
Principles and patterns for test driven developmentStephen Fuqua
 
An Introduction to Unit Test Using NUnit
An Introduction to Unit Test Using NUnitAn Introduction to Unit Test Using NUnit
An Introduction to Unit Test Using NUnitweili_at_slideshare
 
Clean Unit Test Patterns
Clean Unit Test PatternsClean Unit Test Patterns
Clean Unit Test PatternsFrank Appel
 
Unit testing best practices
Unit testing best practicesUnit testing best practices
Unit testing best practicesnickokiss
 
Unit Testing Concepts and Best Practices
Unit Testing Concepts and Best PracticesUnit Testing Concepts and Best Practices
Unit Testing Concepts and Best PracticesDerek Smith
 
Undertaking Cemetery Rehabilitation
Undertaking  Cemetery RehabilitationUndertaking  Cemetery Rehabilitation
Undertaking Cemetery Rehabilitationchicora
 
Ramesh Curriculum Vitae
Ramesh Curriculum VitaeRamesh Curriculum Vitae
Ramesh Curriculum Vitaeramesh77uom
 
Gei015.09 Seminar032409
Gei015.09 Seminar032409Gei015.09 Seminar032409
Gei015.09 Seminar032409sourcelv
 
09April2009 Assembly Presentation
09April2009   Assembly Presentation09April2009   Assembly Presentation
09April2009 Assembly Presentationnurarafah
 
Ataqueal Coraz N
Ataqueal Coraz NAtaqueal Coraz N
Ataqueal Coraz Namigo2007
 

Viewers also liked (20)

Introduction to F#
Introduction to F#Introduction to F#
Introduction to F#
 
F# intro
F# introF# intro
F# intro
 
Sequential file programming patterns and performance with .net
Sequential  file programming patterns and performance with .netSequential  file programming patterns and performance with .net
Sequential file programming patterns and performance with .net
 
Moq Presentation
Moq PresentationMoq Presentation
Moq Presentation
 
Mock driven development using .NET
Mock driven development using .NETMock driven development using .NET
Mock driven development using .NET
 
Domain Driven Design with the F# type System -- NDC London 2013
Domain Driven Design with the F# type System -- NDC London 2013Domain Driven Design with the F# type System -- NDC London 2013
Domain Driven Design with the F# type System -- NDC London 2013
 
Functional Programming in C# and F#
Functional Programming in C# and F#Functional Programming in C# and F#
Functional Programming in C# and F#
 
Principles and patterns for test driven development
Principles and patterns for test driven developmentPrinciples and patterns for test driven development
Principles and patterns for test driven development
 
Unit Testing (C#)
Unit Testing (C#)Unit Testing (C#)
Unit Testing (C#)
 
TDD, BDD and mocks
TDD, BDD and mocksTDD, BDD and mocks
TDD, BDD and mocks
 
An Introduction to Unit Test Using NUnit
An Introduction to Unit Test Using NUnitAn Introduction to Unit Test Using NUnit
An Introduction to Unit Test Using NUnit
 
Clean Unit Test Patterns
Clean Unit Test PatternsClean Unit Test Patterns
Clean Unit Test Patterns
 
Unit testing best practices
Unit testing best practicesUnit testing best practices
Unit testing best practices
 
Unit Testing Concepts and Best Practices
Unit Testing Concepts and Best PracticesUnit Testing Concepts and Best Practices
Unit Testing Concepts and Best Practices
 
Undertaking Cemetery Rehabilitation
Undertaking  Cemetery RehabilitationUndertaking  Cemetery Rehabilitation
Undertaking Cemetery Rehabilitation
 
CRM
CRMCRM
CRM
 
Ramesh Curriculum Vitae
Ramesh Curriculum VitaeRamesh Curriculum Vitae
Ramesh Curriculum Vitae
 
Gei015.09 Seminar032409
Gei015.09 Seminar032409Gei015.09 Seminar032409
Gei015.09 Seminar032409
 
09April2009 Assembly Presentation
09April2009   Assembly Presentation09April2009   Assembly Presentation
09April2009 Assembly Presentation
 
Ataqueal Coraz N
Ataqueal Coraz NAtaqueal Coraz N
Ataqueal Coraz N
 

Similar to F# Presentation

Similar to F# Presentation (20)

Python quickstart for programmers: Python Kung Fu
Python quickstart for programmers: Python Kung FuPython quickstart for programmers: Python Kung Fu
Python quickstart for programmers: Python Kung Fu
 
Scala 2 + 2 > 4
Scala 2 + 2 > 4Scala 2 + 2 > 4
Scala 2 + 2 > 4
 
Kotlin
KotlinKotlin
Kotlin
 
Ruby Language - A quick tour
Ruby Language - A quick tourRuby Language - A quick tour
Ruby Language - A quick tour
 
Scala introduction
Scala introductionScala introduction
Scala introduction
 
Python for High School Programmers
Python for High School ProgrammersPython for High School Programmers
Python for High School Programmers
 
JBUG 11 - Scala For Java Programmers
JBUG 11 - Scala For Java ProgrammersJBUG 11 - Scala For Java Programmers
JBUG 11 - Scala For Java Programmers
 
Groovy
GroovyGroovy
Groovy
 
C tutorial
C tutorialC tutorial
C tutorial
 
Python Workshop
Python  Workshop Python  Workshop
Python Workshop
 
Python
PythonPython
Python
 
LEX & YACC TOOL
LEX & YACC TOOLLEX & YACC TOOL
LEX & YACC TOOL
 
My First Rails Plugin - Usertext
My First Rails Plugin - UsertextMy First Rails Plugin - Usertext
My First Rails Plugin - Usertext
 
C to perl binding
C to perl bindingC to perl binding
C to perl binding
 
Python Workshop Part 2. LUG Maniapl
Python Workshop Part 2. LUG ManiaplPython Workshop Part 2. LUG Maniapl
Python Workshop Part 2. LUG Maniapl
 
Falcon初印象
Falcon初印象Falcon初印象
Falcon初印象
 
Functional Programming in F#
Functional Programming in F#Functional Programming in F#
Functional Programming in F#
 
Bti1022 lab sheet 8
Bti1022 lab sheet 8Bti1022 lab sheet 8
Bti1022 lab sheet 8
 
Bti1022 lab sheet 8
Bti1022 lab sheet 8Bti1022 lab sheet 8
Bti1022 lab sheet 8
 
SWP - A Generic Language Parser
SWP - A Generic Language ParserSWP - A Generic Language Parser
SWP - A Generic Language Parser
 

Recently uploaded

From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch TuesdayIvanti
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 
Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Farhan Tariq
 
Assure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyesAssure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyesThousandEyes
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 
Testing tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesTesting tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesKari Kakkonen
 
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Mark Goldstein
 
UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPathCommunity
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...Wes McKinney
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
Connecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfConnecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfNeo4j
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 
Manual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance AuditManual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance AuditSkynet Technologies
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI AgeCprime
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demoHarshalMandlekar2
 
Decarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityDecarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityIES VE
 
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Alkin Tezuysal
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxLoriGlavin3
 
Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Hiroshi SHIBATA
 

Recently uploaded (20)

From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch Tuesday
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 
Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...
 
Assure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyesAssure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyes
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 
Testing tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesTesting tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examples
 
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
 
UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to Hero
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
Connecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfConnecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdf
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 
Manual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance AuditManual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance Audit
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI Age
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demo
 
Decarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityDecarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a reality
 
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptx
 
Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024
 

F# Presentation

  • 1. A language you can brag about
  • 2. Functional programming   The new hotness Next “big” .NET language   CTP this summer
  • 3. OCaml offspring  Created by MS Research  Mixed mode language   Functional  OO  Imperative (if you must) Statically typed 
  • 4. Yay! Type inference  let x = 7 ...also, immutable  let s = quot;kurtquot; let pi = 3.142 So, really just “values” 
  • 5. let l = ['a';'b';'c';] // char list or list<char> Singly linked list  Still immutable!  let digits = [0..9] // int list
  • 6. IEnumerable<T>  let s = {1..10} Useful for computing  // seq[1;2;3;...] unbounded lists
  • 7. let me = (quot;kurtquot;, 6.0) Typed groups of values  // string * float Can “hold” anything  let point3d = (0,0,0) Basically awesome  // int * int * int
  • 8. let add x y = x + y Like any other value  // int -> int -> int More type inference  let eight = add 3 5 Returns last expression  // eight = 8
  • 9. Look ma! Generics!  let group x y = (x,y) // 'a -> 'b -> 'a * 'b  Auto-generalization
  • 10. let rec fib n = if n < 2 then n Explicitly recursive  else Tail recursion  (fib (n - 1)) + (fib (n - 2))
  • 11. type name = string type number = int type date = System.DateTime type meeting = | Personal of name * date | Phone of number * date let review = Personal(quot;Jasminequot;,System.DateTime.Now) let call = Phone(8675309, System.DateTime.Now)
  • 12. let what_to_do (m : meeting) = match m with | Personal(name,date) -> printfn quot;Meeting with %s at %Aquot; name date | Phone(phone, date) -> printfn quot;Call %A at %Aquot; phone date
  • 13. Functions are basic units of a program  We can mix them up in interesting ways   Less OO design patterns! “Cheap” functions are good   Code is more expressive
  • 14. let add3 = add 3 let add x y = x + y // int -> int // int -> int -> int
  • 15. let even x = x % 2 = 0 // int -> bool let numbers = [1..20] let (|>) x f = f x // int list let evens = // 'a -> ('a -> 'b) -> 'b numbers |> List.filter even // int list
  • 16. List.fold_left // ('b -> 'a -> 'b) -> List.map // 'b -> // ('a -> 'b) -> // 'a list -> // 'a list -> // 'b // 'b list [1..10] |> List.fold_left [1..10] |> List.map add3 (fun acc x -> acc + x) 0 // [4;5;6;..;13] // 55
  • 17. 2520 is the smallest number that can be  divided by each of the numbers from 1 to 10 without any remainder. What is the smallest number that is evenly  divisible by all of the numbers from 1 to 20? - Project Euler projecteuler.net
  • 18. “Mutable” keyword   For real variables There are imperative loops   Try not to use it too much
  • 19. F# can be OO   Classes  Interfaces  Inheritance Cross language work   “Hide” implementation
  • 20. type OrderLine(n:string, q:int, p:float) = let mutable currName = n let mutable currQuantity = q let mutable currPrice = p new (name, price) = OrderLine(name, 1, price) member x.Name with get() = currName and set name = currName <- name member x.SubTotal with get() = (Float.of_int quantity) * price member x.OneMore() = currQuantity <- currQuantity + 1 currQuantity
  • 21. Why functional programming?   Easy to build incrementally  Simplified testing  Concurrency! Imperative can be good too   At times, it’s wickedly fast  It’s what we know