SlideShare une entreprise Scribd logo
1  sur  32
F# for Functional Enthusiasts
Jack Fox
jackfoxy.com  craftyThoughts
@foxyjackfox
Bibliography
jackfoxy.com/Fsharp_functional_enthusiasts_bibliography
Sample Code
https://gist.github.com/jackfoxy/6679238
https://github.com/jackfoxy/CrockSolution
https://github.com/jackfoxy/TestSandbox
2012 annular eclipse observed by the author from Sugarloaf Peak, Lake Shasta
Type Providers
Microsoft.FSharp.Data.TypeProviders
DbmlFile
EdmxFile
ODataService
SqlDataConnection
SqlEntityConnection
WsdlService
Fsharpx
AppSettings
Excel
Graph
Machine
Management
Math
Regex
Xaml
Xrm
FSharp.Data
Apiary
Csv
Freebase
Json
WorldBank
Xml
F# 3.0 Sample Pack
DGML
Word
Csv
DataStore
Hadoop/Hive/Hdfs
HelloWorld
Management
MiniCvs
Xrm
Tsunami
RSS Reader
Start Menu
NuGetTypeProvider *
S3TypeProvider *
FacebookTypeProvider *
DocumentTypeProvider *
* (samples inside Tsunami)
in the wild on Github
FunScript
R
Matlab
IKVM (Java)
Python
PowerShell
strongly typed ≠ object oriented
Typed Clojure project on indiegogo.com
Parameterized Polymorphism
a.k.a. Generics
let inline unsigned bitSize (zero : 'a) (one : 'a) =
let one' = one + zero
let x' = one <<< (bitSize - 1)
x' ||| one'
bitSize:int -> zero: ^a -> one: ^a -> ^a
when ^a : (static member ( + ) : ^a * ^a -> ^a) and
^a : (static member ( <<< ) : ^a * int32 -> ^a) and
^a : (static member ( ||| ) : ^a * ^a -> ^a)
// Base Type Constraint
type Class1<'T when 'T :> System.Exception> …
// Interface Type Constraint
type Class2<'T when 'T :> System.IComparable> …
// Comparison constraint
type Class10<'T when 'T : comparison> …
// Member constraint with property
type Class6<'T when 'T : (member Property1 : int)> …
Constraints on Type Definitions
[<Measure>] type m // Distance, meters.
[<Measure>] type mile // Distance, miles.
[<Measure>] type s // Time, seconds.
[<Measure>] type h // Time, hours.
let distance1 = 100.0<m>
let distance2 = 250.0<mile>
let speedMetersPerSec = distance1 / 10.0<s> // float<m/s>
let speedMPH = distance2 / 5.0<h> // float<mile/h>
let x = distance1 + distance2 //will not compile
Units of Measure
Design Time Type Checking
So far…
Type Providers: strongly typed external data
Strong typing and type inference
Type constraints
Units of Measure
Next up…
Nuts and bolts programming
Vector
Eager Rose Tree
Vector
54321
Construct
Deconstruct
Initia
l
Las
t
[ ]
empt
y
;
;
type JsonValue =
| String of string
| Number of decimal
| Float of float
| Object of Map<string, JsonValue>
| Array of JsonValue[]
| Boolean of bool
| Null
JSON Parsing
Discriminated Union Type from
FSharp.Data
JSON Parsing
Demo Crock Solution
FSI (REPL) compiles to assembly and executes
F# scripts
Fseye
Triple quoting
Red Black Tree Balancing
Source: https://wiki.rice.edu/confluence/download/attachments/2761212/Okasaki-Red-Black.pdf
a b
c
d
b ca d
a
a
b c
d
b c
d
a
c
b
d
Talk about reducing complexity!
type 'a t = Node of color * 'a * 'a t * 'a t | Leaf
let balance = function
| Black, z, Node (Red, y, Node (Red, x, a, b), c), d
| Black, z, Node (Red, x, a, Node (Red, y, b, c)), d
| Black, x, a, Node (Red, z, Node (Red, y, b, c), d)
| Black, x, a, Node (Red, y, b, Node (Red, z, c, d)) ->
Node (Red, y, Node (Black, x, a, b), Node (Black, z, c, d))
| x -> Node x
Source: http://fsharpnews.blogspot.com/2010/07/f-vs-mathematica-red-black-
trees.html
Computational Expressions
One syntactic sugar to rule them all
( monad, monoid, applicative functor )
seq {for n in 1..10 do
yield n
yield n * 2}
seq {for n in 1..10 do
yield (n, n * 2)}
Sequence Generators
Computational Expressions
Recursive Generators
let rec listFiles dir = seq {
yield! Directory.GetFiles(dir)
for subdir in Directory.GetDirectories(dir) do
yield! listFiles subdir }
let musicFiles = listFiles "E:music" |> List.ofSeq
Computational Expressions
Query Expressions
let htmlPage =
query { for content in db.tbContentLib do
where (content.companyID.Value > 0 and content.isHtml)
join template in db.tbTemplate on
(content.templateID.Value = template.templateID)
select (content.styleID, template.title, template.body)
}
Computational Expressions
Query Expressions (Freebase)
let topBooksWithNameContaining (s:string) =
query { for book in
data.``Arts and Entertainment``.Books.Books
do
where (book.Name.ApproximatelyMatches s)
take 10
select book.Name }
Async
let someBinding =
async {
let! x = … // asynchronous binding
let y = … // synchronous binding
let! z = … // another asynchronous binding
do! … // asynchronous execution
return z // return something (or not)
}
Agents
a.k.a. Mailbox Processor
Message passing
Actor Model
Erlang-like processing
{m}brace
Cloud Computing (beta)
[<Cloud>]
let calculatePi (iterations : bigint) (digits : int) : ICloud<string> =
cloud {
let! workers = Cloud.GetWorkerCount()
let workers = bigint (2 * workers)
...
let runWorker iterations = cloud { return monteCarloPiWorker iterations }
let! results =
...
|> Cloud.Parallel
...
return getDigits a b
|> ...
}
Quotations
let ``Vector<Vector<'T>>, windowSeq``() =
test<@ [0; 1; 2; 3; 4; 5; 6; 7; 8; 9; 10;] =
([0; 1; 2; 3; 4; 5; 6; 7; 8; 9; ]
|> Vector.windowSeq 3
|> Vector.flatten
|> List.ofSeq) @>
Now we’ve seen…
ML-style pattern matching
Syntactic sugar over common FP abstractions
Async and friends
Quotations
Next: Community-Driven Development
Fsharp.org
Some “core” projects
Dev environments
Fsharp.org
F# Foundation
Owns resources relating to F# including:
the domain fsharp.org
the github.com/fsharp community organization
the fsharporg twitter account
Seeks to:
promote the adoption of F#
expand the relevance and importance of F# skills and knowledge
expand the range of technologies which can interoperate with F#
expand the range of platforms where F# can be used
facilitate the ongoing development of F#-related technology and resources
FAKE
 DSL implementation of build automation system
 Full use of F# language
 Access to any and all libraries
 Develop with powerful debuggers and IDEs
Literate Programming
FSharp.Formatting
Funscript
Javascript and Single Page Apps
JQuery and Javascript DOM APIs
TypeScript TypeProvider
Mini Web Server
Websharper
Fully composeable client-server web development.
#websharper on irc.freenode.net
GPU Process
Alea.cuBase
Complete commercial solution to develop highly optimized
CUDA accelerated GPU applications from F# quotations by
QuantAlea.
Advantages of functional composition and rapid prototyping
Don’t have a NVIDIA card?
Try Brahma.Fsharp F# quotations to OpenCL translation
Testing Options
FsUnit – native F# functional syntax across test tools
FsCheck – QuickCheck for F#
TickSpec – lightweight, but fully featured Gherkin BDD
Canopy – lightweight F# syntax for web-client Selenium testing
Unquote – step-by-step F# expression evaluations
Development Alternatives
Tsunami IDE (beta)
Visual Studio 2010, 2012, 2013 (free Express edition)
Xamarin Studio -- iOS, Android, Mac, Mono, .NET
(free edition limits project size)
Emacs
Vim
SublimeText
IKVM lets Java and .NET Get Along!
Java from .NET, .NET from Java
JVM bytecode  IL instruction  native JIT
(not a bunch of wrappers)
10+ years of development effort
Actively supported
Powers Mono
Extremely few edge incompatibilities
Questions?
F# Programming
http://en.wikibooks.org/wiki/F_Sharp_Programming
A Course of F# Study
http://jackfoxy.com/a-course-of-fsharp-study
A directory of useful pages
http://fsharpforfunandprofit.com/site-contents
Learning F#

Contenu connexe

Tendances

Crystal presentation in NY
Crystal presentation in NYCrystal presentation in NY
Crystal presentation in NYCrystal Language
 
Making Your Own Domain Specific Language
Making Your Own Domain Specific LanguageMaking Your Own Domain Specific Language
Making Your Own Domain Specific LanguageAncestry.com
 
Introduction to Programming in LISP
Introduction to Programming in LISPIntroduction to Programming in LISP
Introduction to Programming in LISPKnoldus Inc.
 
Understanding Hadoop through examples
Understanding Hadoop through examplesUnderstanding Hadoop through examples
Understanding Hadoop through examplesYoshitomo Matsubara
 
Python courses: lecture 1
Python courses: lecture 1Python courses: lecture 1
Python courses: lecture 1Ihor Khytrykh
 
Mapping Hierarchical Sources into RDF using the RML Mapping Language
Mapping Hierarchical Sources into RDF using the RML Mapping LanguageMapping Hierarchical Sources into RDF using the RML Mapping Language
Mapping Hierarchical Sources into RDF using the RML Mapping Languageandimou
 
CSS: The Boring Bits
CSS: The Boring BitsCSS: The Boring Bits
CSS: The Boring BitsPeter Gasston
 
Exploring C# DSLs: LINQ, Fluent Interfaces and Expression Trees
Exploring C# DSLs: LINQ, Fluent Interfaces and Expression TreesExploring C# DSLs: LINQ, Fluent Interfaces and Expression Trees
Exploring C# DSLs: LINQ, Fluent Interfaces and Expression Treesrasmuskl
 
Introduction to D programming language at Weka.IO
Introduction to D programming language at Weka.IOIntroduction to D programming language at Weka.IO
Introduction to D programming language at Weka.IOLiran Zvibel
 
Data compression tech cs
Data compression tech csData compression tech cs
Data compression tech cschirag1823
 
Functional Programming #FTW
Functional Programming #FTWFunctional Programming #FTW
Functional Programming #FTWAdriano Bonat
 
Hourglass Interfaces for C++ APIs - CppCon 2014
Hourglass Interfaces for C++ APIs - CppCon 2014Hourglass Interfaces for C++ APIs - CppCon 2014
Hourglass Interfaces for C++ APIs - CppCon 2014Stefanus Du Toit
 
INTRODUCTION TO LISP
INTRODUCTION TO LISPINTRODUCTION TO LISP
INTRODUCTION TO LISPNilt1234
 
IronPython and Dynamic Languages on .NET by Mahesh Prakriya
 IronPython and Dynamic Languages on .NET by Mahesh Prakriya IronPython and Dynamic Languages on .NET by Mahesh Prakriya
IronPython and Dynamic Languages on .NET by Mahesh Prakriyacodebits
 
The GNOME way - What can we learn from and within the Open Documentation World
The GNOME way - What can we learn from and within the Open Documentation WorldThe GNOME way - What can we learn from and within the Open Documentation World
The GNOME way - What can we learn from and within the Open Documentation WorldRadina Matic
 

Tendances (20)

Crystal presentation in NY
Crystal presentation in NYCrystal presentation in NY
Crystal presentation in NY
 
D programming language
D programming languageD programming language
D programming language
 
Introduction to R
Introduction to RIntroduction to R
Introduction to R
 
Making Your Own Domain Specific Language
Making Your Own Domain Specific LanguageMaking Your Own Domain Specific Language
Making Your Own Domain Specific Language
 
Introduction to Programming in LISP
Introduction to Programming in LISPIntroduction to Programming in LISP
Introduction to Programming in LISP
 
Understanding Hadoop through examples
Understanding Hadoop through examplesUnderstanding Hadoop through examples
Understanding Hadoop through examples
 
Python courses: lecture 1
Python courses: lecture 1Python courses: lecture 1
Python courses: lecture 1
 
Mapping Hierarchical Sources into RDF using the RML Mapping Language
Mapping Hierarchical Sources into RDF using the RML Mapping LanguageMapping Hierarchical Sources into RDF using the RML Mapping Language
Mapping Hierarchical Sources into RDF using the RML Mapping Language
 
CSS: The Boring Bits
CSS: The Boring BitsCSS: The Boring Bits
CSS: The Boring Bits
 
Exploring C# DSLs: LINQ, Fluent Interfaces and Expression Trees
Exploring C# DSLs: LINQ, Fluent Interfaces and Expression TreesExploring C# DSLs: LINQ, Fluent Interfaces and Expression Trees
Exploring C# DSLs: LINQ, Fluent Interfaces and Expression Trees
 
Introduction to D programming language at Weka.IO
Introduction to D programming language at Weka.IOIntroduction to D programming language at Weka.IO
Introduction to D programming language at Weka.IO
 
Data compression tech cs
Data compression tech csData compression tech cs
Data compression tech cs
 
LISP: Introduction to lisp
LISP: Introduction to lispLISP: Introduction to lisp
LISP: Introduction to lisp
 
Functional Programming #FTW
Functional Programming #FTWFunctional Programming #FTW
Functional Programming #FTW
 
Exop ❤️ StreamData
Exop ❤️ StreamDataExop ❤️ StreamData
Exop ❤️ StreamData
 
Hourglass Interfaces for C++ APIs - CppCon 2014
Hourglass Interfaces for C++ APIs - CppCon 2014Hourglass Interfaces for C++ APIs - CppCon 2014
Hourglass Interfaces for C++ APIs - CppCon 2014
 
INTRODUCTION TO LISP
INTRODUCTION TO LISPINTRODUCTION TO LISP
INTRODUCTION TO LISP
 
IronPython and Dynamic Languages on .NET by Mahesh Prakriya
 IronPython and Dynamic Languages on .NET by Mahesh Prakriya IronPython and Dynamic Languages on .NET by Mahesh Prakriya
IronPython and Dynamic Languages on .NET by Mahesh Prakriya
 
The GNOME way - What can we learn from and within the Open Documentation World
The GNOME way - What can we learn from and within the Open Documentation WorldThe GNOME way - What can we learn from and within the Open Documentation World
The GNOME way - What can we learn from and within the Open Documentation World
 
Kibana: Real-World Examples
Kibana: Real-World ExamplesKibana: Real-World Examples
Kibana: Real-World Examples
 

Similaire à F# for functional enthusiasts

Creating Domain Specific Languages in F#
Creating Domain Specific Languages in F#Creating Domain Specific Languages in F#
Creating Domain Specific Languages in F#Tomas Petricek
 
Programming Languages: some news for the last N years
Programming Languages: some news for the last N yearsProgramming Languages: some news for the last N years
Programming Languages: some news for the last N yearsRuslan Shevchenko
 
Accessing loosely structured data from F# and C#
Accessing loosely structured data from F# and C#Accessing loosely structured data from F# and C#
Accessing loosely structured data from F# and C#Tomas Petricek
 
Visual Studio .NET2010
Visual Studio .NET2010Visual Studio .NET2010
Visual Studio .NET2010Satish Verma
 
TI1220 Lecture 14: Domain-Specific Languages
TI1220 Lecture 14: Domain-Specific LanguagesTI1220 Lecture 14: Domain-Specific Languages
TI1220 Lecture 14: Domain-Specific LanguagesEelco Visser
 
SF Elixir Meetup - RethinkDB
SF Elixir Meetup - RethinkDBSF Elixir Meetup - RethinkDB
SF Elixir Meetup - RethinkDBPeter Hamilton
 
"The F# Path to Relaxation", Don Syme
"The F# Path to Relaxation", Don Syme"The F# Path to Relaxation", Don Syme
"The F# Path to Relaxation", Don SymeFwdays
 
Building Kafka Connectors with Kotlin: A Step-by-Step Guide to Creation and D...
Building Kafka Connectors with Kotlin: A Step-by-Step Guide to Creation and D...Building Kafka Connectors with Kotlin: A Step-by-Step Guide to Creation and D...
Building Kafka Connectors with Kotlin: A Step-by-Step Guide to Creation and D...HostedbyConfluent
 
Groovy Update - JavaPolis 2007
Groovy Update - JavaPolis 2007Groovy Update - JavaPolis 2007
Groovy Update - JavaPolis 2007Guillaume Laforge
 
Apache Spark Workshop, Apr. 2016, Euangelos Linardos
Apache Spark Workshop, Apr. 2016, Euangelos LinardosApache Spark Workshop, Apr. 2016, Euangelos Linardos
Apache Spark Workshop, Apr. 2016, Euangelos LinardosEuangelos Linardos
 
Data science at the command line
Data science at the command lineData science at the command line
Data science at the command lineSharat Chikkerur
 
iOS App Development with F# and Xamarin
iOS App Development with F# and XamariniOS App Development with F# and Xamarin
iOS App Development with F# and XamarinRachel Reese
 
Language-agnostic data analysis workflows and reproducible research
Language-agnostic data analysis workflows and reproducible researchLanguage-agnostic data analysis workflows and reproducible research
Language-agnostic data analysis workflows and reproducible researchAndrew Lowe
 
Building DSLs On CLR and DLR (Microsoft.NET)
Building DSLs On CLR and DLR (Microsoft.NET)Building DSLs On CLR and DLR (Microsoft.NET)
Building DSLs On CLR and DLR (Microsoft.NET)Vitaly Baum
 
Transformation Processing Smackdown; Spark vs Hive vs Pig
Transformation Processing Smackdown; Spark vs Hive vs PigTransformation Processing Smackdown; Spark vs Hive vs Pig
Transformation Processing Smackdown; Spark vs Hive vs PigLester Martin
 
SparkR: Enabling Interactive Data Science at Scale on Hadoop
SparkR: Enabling Interactive Data Science at Scale on HadoopSparkR: Enabling Interactive Data Science at Scale on Hadoop
SparkR: Enabling Interactive Data Science at Scale on HadoopDataWorks Summit
 
Alpine academy apache spark series #1 introduction to cluster computing wit...
Alpine academy apache spark series #1   introduction to cluster computing wit...Alpine academy apache spark series #1   introduction to cluster computing wit...
Alpine academy apache spark series #1 introduction to cluster computing wit...Holden Karau
 
.NET and C# introduction
.NET and C# introduction.NET and C# introduction
.NET and C# introductionPeter Gfader
 
Orchestrating the Intelligent Web with Apache Mahout
Orchestrating the Intelligent Web with Apache MahoutOrchestrating the Intelligent Web with Apache Mahout
Orchestrating the Intelligent Web with Apache Mahoutaneeshabakharia
 

Similaire à F# for functional enthusiasts (20)

Creating Domain Specific Languages in F#
Creating Domain Specific Languages in F#Creating Domain Specific Languages in F#
Creating Domain Specific Languages in F#
 
Programming Languages: some news for the last N years
Programming Languages: some news for the last N yearsProgramming Languages: some news for the last N years
Programming Languages: some news for the last N years
 
Accessing loosely structured data from F# and C#
Accessing loosely structured data from F# and C#Accessing loosely structured data from F# and C#
Accessing loosely structured data from F# and C#
 
Visual Studio .NET2010
Visual Studio .NET2010Visual Studio .NET2010
Visual Studio .NET2010
 
F# and the DLR
F# and the DLRF# and the DLR
F# and the DLR
 
TI1220 Lecture 14: Domain-Specific Languages
TI1220 Lecture 14: Domain-Specific LanguagesTI1220 Lecture 14: Domain-Specific Languages
TI1220 Lecture 14: Domain-Specific Languages
 
SF Elixir Meetup - RethinkDB
SF Elixir Meetup - RethinkDBSF Elixir Meetup - RethinkDB
SF Elixir Meetup - RethinkDB
 
"The F# Path to Relaxation", Don Syme
"The F# Path to Relaxation", Don Syme"The F# Path to Relaxation", Don Syme
"The F# Path to Relaxation", Don Syme
 
Building Kafka Connectors with Kotlin: A Step-by-Step Guide to Creation and D...
Building Kafka Connectors with Kotlin: A Step-by-Step Guide to Creation and D...Building Kafka Connectors with Kotlin: A Step-by-Step Guide to Creation and D...
Building Kafka Connectors with Kotlin: A Step-by-Step Guide to Creation and D...
 
Groovy Update - JavaPolis 2007
Groovy Update - JavaPolis 2007Groovy Update - JavaPolis 2007
Groovy Update - JavaPolis 2007
 
Apache Spark Workshop, Apr. 2016, Euangelos Linardos
Apache Spark Workshop, Apr. 2016, Euangelos LinardosApache Spark Workshop, Apr. 2016, Euangelos Linardos
Apache Spark Workshop, Apr. 2016, Euangelos Linardos
 
Data science at the command line
Data science at the command lineData science at the command line
Data science at the command line
 
iOS App Development with F# and Xamarin
iOS App Development with F# and XamariniOS App Development with F# and Xamarin
iOS App Development with F# and Xamarin
 
Language-agnostic data analysis workflows and reproducible research
Language-agnostic data analysis workflows and reproducible researchLanguage-agnostic data analysis workflows and reproducible research
Language-agnostic data analysis workflows and reproducible research
 
Building DSLs On CLR and DLR (Microsoft.NET)
Building DSLs On CLR and DLR (Microsoft.NET)Building DSLs On CLR and DLR (Microsoft.NET)
Building DSLs On CLR and DLR (Microsoft.NET)
 
Transformation Processing Smackdown; Spark vs Hive vs Pig
Transformation Processing Smackdown; Spark vs Hive vs PigTransformation Processing Smackdown; Spark vs Hive vs Pig
Transformation Processing Smackdown; Spark vs Hive vs Pig
 
SparkR: Enabling Interactive Data Science at Scale on Hadoop
SparkR: Enabling Interactive Data Science at Scale on HadoopSparkR: Enabling Interactive Data Science at Scale on Hadoop
SparkR: Enabling Interactive Data Science at Scale on Hadoop
 
Alpine academy apache spark series #1 introduction to cluster computing wit...
Alpine academy apache spark series #1   introduction to cluster computing wit...Alpine academy apache spark series #1   introduction to cluster computing wit...
Alpine academy apache spark series #1 introduction to cluster computing wit...
 
.NET and C# introduction
.NET and C# introduction.NET and C# introduction
.NET and C# introduction
 
Orchestrating the Intelligent Web with Apache Mahout
Orchestrating the Intelligent Web with Apache MahoutOrchestrating the Intelligent Web with Apache Mahout
Orchestrating the Intelligent Web with Apache Mahout
 

Plus de Jack Fox

Dependent Types make bad data unrepresentable
Dependent Types make bad data unrepresentableDependent Types make bad data unrepresentable
Dependent Types make bad data unrepresentableJack Fox
 
Dependent Types
Dependent TypesDependent Types
Dependent TypesJack Fox
 
Introduction to the lambda calculus
Introduction to the lambda calculusIntroduction to the lambda calculus
Introduction to the lambda calculusJack Fox
 
Tools for reading papers
Tools for reading papersTools for reading papers
Tools for reading papersJack Fox
 
Functional programming for production quality code
Functional programming for production quality codeFunctional programming for production quality code
Functional programming for production quality codeJack Fox
 
Intoduction to Homotopy Type Therory
Intoduction to Homotopy Type TheroryIntoduction to Homotopy Type Therory
Intoduction to Homotopy Type TheroryJack Fox
 
Type Theory and Practical Application
Type Theory and Practical ApplicationType Theory and Practical Application
Type Theory and Practical ApplicationJack Fox
 
Semantically coherent functional linear data structures
Semantically coherent functional linear data structuresSemantically coherent functional linear data structures
Semantically coherent functional linear data structuresJack Fox
 
Linear structures lightning talk
Linear structures lightning talkLinear structures lightning talk
Linear structures lightning talkJack Fox
 
Functional linear data structures in f#
Functional linear data structures in f#Functional linear data structures in f#
Functional linear data structures in f#Jack Fox
 

Plus de Jack Fox (10)

Dependent Types make bad data unrepresentable
Dependent Types make bad data unrepresentableDependent Types make bad data unrepresentable
Dependent Types make bad data unrepresentable
 
Dependent Types
Dependent TypesDependent Types
Dependent Types
 
Introduction to the lambda calculus
Introduction to the lambda calculusIntroduction to the lambda calculus
Introduction to the lambda calculus
 
Tools for reading papers
Tools for reading papersTools for reading papers
Tools for reading papers
 
Functional programming for production quality code
Functional programming for production quality codeFunctional programming for production quality code
Functional programming for production quality code
 
Intoduction to Homotopy Type Therory
Intoduction to Homotopy Type TheroryIntoduction to Homotopy Type Therory
Intoduction to Homotopy Type Therory
 
Type Theory and Practical Application
Type Theory and Practical ApplicationType Theory and Practical Application
Type Theory and Practical Application
 
Semantically coherent functional linear data structures
Semantically coherent functional linear data structuresSemantically coherent functional linear data structures
Semantically coherent functional linear data structures
 
Linear structures lightning talk
Linear structures lightning talkLinear structures lightning talk
Linear structures lightning talk
 
Functional linear data structures in f#
Functional linear data structures in f#Functional linear data structures in f#
Functional linear data structures in f#
 

Dernier

TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
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
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
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
 
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better StrongerModern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better Strongerpanagenda
 
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
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
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
 
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
 
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality AssuranceInflectra
 
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
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersRaghuram Pandurangan
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesThousandEyes
 
Scale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterScale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterMydbops
 
Data governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationData governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationKnoldus Inc.
 
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
 
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
 
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
 
Manual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance AuditManual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance AuditSkynet Technologies
 

Dernier (20)

TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
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...
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
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
 
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better StrongerModern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
 
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
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
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
 
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
 
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
 
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
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information Developers
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
 
Scale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterScale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL Router
 
Data governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationData governance with Unity Catalog Presentation
Data governance with Unity Catalog Presentation
 
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
 
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...
 
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
 
Manual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance AuditManual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance Audit
 

F# for functional enthusiasts

  • 1. F# for Functional Enthusiasts Jack Fox jackfoxy.com  craftyThoughts @foxyjackfox Bibliography jackfoxy.com/Fsharp_functional_enthusiasts_bibliography Sample Code https://gist.github.com/jackfoxy/6679238 https://github.com/jackfoxy/CrockSolution https://github.com/jackfoxy/TestSandbox 2012 annular eclipse observed by the author from Sugarloaf Peak, Lake Shasta
  • 2. Type Providers Microsoft.FSharp.Data.TypeProviders DbmlFile EdmxFile ODataService SqlDataConnection SqlEntityConnection WsdlService Fsharpx AppSettings Excel Graph Machine Management Math Regex Xaml Xrm FSharp.Data Apiary Csv Freebase Json WorldBank Xml F# 3.0 Sample Pack DGML Word Csv DataStore Hadoop/Hive/Hdfs HelloWorld Management MiniCvs Xrm Tsunami RSS Reader Start Menu NuGetTypeProvider * S3TypeProvider * FacebookTypeProvider * DocumentTypeProvider * * (samples inside Tsunami) in the wild on Github FunScript R Matlab IKVM (Java) Python PowerShell
  • 3. strongly typed ≠ object oriented Typed Clojure project on indiegogo.com
  • 4. Parameterized Polymorphism a.k.a. Generics let inline unsigned bitSize (zero : 'a) (one : 'a) = let one' = one + zero let x' = one <<< (bitSize - 1) x' ||| one' bitSize:int -> zero: ^a -> one: ^a -> ^a when ^a : (static member ( + ) : ^a * ^a -> ^a) and ^a : (static member ( <<< ) : ^a * int32 -> ^a) and ^a : (static member ( ||| ) : ^a * ^a -> ^a)
  • 5. // Base Type Constraint type Class1<'T when 'T :> System.Exception> … // Interface Type Constraint type Class2<'T when 'T :> System.IComparable> … // Comparison constraint type Class10<'T when 'T : comparison> … // Member constraint with property type Class6<'T when 'T : (member Property1 : int)> … Constraints on Type Definitions
  • 6. [<Measure>] type m // Distance, meters. [<Measure>] type mile // Distance, miles. [<Measure>] type s // Time, seconds. [<Measure>] type h // Time, hours. let distance1 = 100.0<m> let distance2 = 250.0<mile> let speedMetersPerSec = distance1 / 10.0<s> // float<m/s> let speedMPH = distance2 / 5.0<h> // float<mile/h> let x = distance1 + distance2 //will not compile Units of Measure Design Time Type Checking
  • 7. So far… Type Providers: strongly typed external data Strong typing and type inference Type constraints Units of Measure Next up… Nuts and bolts programming
  • 10. type JsonValue = | String of string | Number of decimal | Float of float | Object of Map<string, JsonValue> | Array of JsonValue[] | Boolean of bool | Null JSON Parsing Discriminated Union Type from FSharp.Data
  • 11. JSON Parsing Demo Crock Solution FSI (REPL) compiles to assembly and executes F# scripts Fseye Triple quoting
  • 12. Red Black Tree Balancing Source: https://wiki.rice.edu/confluence/download/attachments/2761212/Okasaki-Red-Black.pdf a b c d b ca d a a b c d b c d a c b d
  • 13. Talk about reducing complexity! type 'a t = Node of color * 'a * 'a t * 'a t | Leaf let balance = function | Black, z, Node (Red, y, Node (Red, x, a, b), c), d | Black, z, Node (Red, x, a, Node (Red, y, b, c)), d | Black, x, a, Node (Red, z, Node (Red, y, b, c), d) | Black, x, a, Node (Red, y, b, Node (Red, z, c, d)) -> Node (Red, y, Node (Black, x, a, b), Node (Black, z, c, d)) | x -> Node x Source: http://fsharpnews.blogspot.com/2010/07/f-vs-mathematica-red-black- trees.html
  • 14. Computational Expressions One syntactic sugar to rule them all ( monad, monoid, applicative functor ) seq {for n in 1..10 do yield n yield n * 2} seq {for n in 1..10 do yield (n, n * 2)} Sequence Generators
  • 15. Computational Expressions Recursive Generators let rec listFiles dir = seq { yield! Directory.GetFiles(dir) for subdir in Directory.GetDirectories(dir) do yield! listFiles subdir } let musicFiles = listFiles "E:music" |> List.ofSeq
  • 16. Computational Expressions Query Expressions let htmlPage = query { for content in db.tbContentLib do where (content.companyID.Value > 0 and content.isHtml) join template in db.tbTemplate on (content.templateID.Value = template.templateID) select (content.styleID, template.title, template.body) }
  • 17. Computational Expressions Query Expressions (Freebase) let topBooksWithNameContaining (s:string) = query { for book in data.``Arts and Entertainment``.Books.Books do where (book.Name.ApproximatelyMatches s) take 10 select book.Name }
  • 18. Async let someBinding = async { let! x = … // asynchronous binding let y = … // synchronous binding let! z = … // another asynchronous binding do! … // asynchronous execution return z // return something (or not) }
  • 19. Agents a.k.a. Mailbox Processor Message passing Actor Model Erlang-like processing
  • 20. {m}brace Cloud Computing (beta) [<Cloud>] let calculatePi (iterations : bigint) (digits : int) : ICloud<string> = cloud { let! workers = Cloud.GetWorkerCount() let workers = bigint (2 * workers) ... let runWorker iterations = cloud { return monteCarloPiWorker iterations } let! results = ... |> Cloud.Parallel ... return getDigits a b |> ... }
  • 21. Quotations let ``Vector<Vector<'T>>, windowSeq``() = test<@ [0; 1; 2; 3; 4; 5; 6; 7; 8; 9; 10;] = ([0; 1; 2; 3; 4; 5; 6; 7; 8; 9; ] |> Vector.windowSeq 3 |> Vector.flatten |> List.ofSeq) @>
  • 22. Now we’ve seen… ML-style pattern matching Syntactic sugar over common FP abstractions Async and friends Quotations Next: Community-Driven Development Fsharp.org Some “core” projects Dev environments
  • 23. Fsharp.org F# Foundation Owns resources relating to F# including: the domain fsharp.org the github.com/fsharp community organization the fsharporg twitter account Seeks to: promote the adoption of F# expand the relevance and importance of F# skills and knowledge expand the range of technologies which can interoperate with F# expand the range of platforms where F# can be used facilitate the ongoing development of F#-related technology and resources
  • 24. FAKE  DSL implementation of build automation system  Full use of F# language  Access to any and all libraries  Develop with powerful debuggers and IDEs
  • 26. Funscript Javascript and Single Page Apps JQuery and Javascript DOM APIs TypeScript TypeProvider Mini Web Server
  • 27. Websharper Fully composeable client-server web development. #websharper on irc.freenode.net
  • 28. GPU Process Alea.cuBase Complete commercial solution to develop highly optimized CUDA accelerated GPU applications from F# quotations by QuantAlea. Advantages of functional composition and rapid prototyping Don’t have a NVIDIA card? Try Brahma.Fsharp F# quotations to OpenCL translation
  • 29. Testing Options FsUnit – native F# functional syntax across test tools FsCheck – QuickCheck for F# TickSpec – lightweight, but fully featured Gherkin BDD Canopy – lightweight F# syntax for web-client Selenium testing Unquote – step-by-step F# expression evaluations
  • 30. Development Alternatives Tsunami IDE (beta) Visual Studio 2010, 2012, 2013 (free Express edition) Xamarin Studio -- iOS, Android, Mac, Mono, .NET (free edition limits project size) Emacs Vim SublimeText
  • 31. IKVM lets Java and .NET Get Along! Java from .NET, .NET from Java JVM bytecode  IL instruction  native JIT (not a bunch of wrappers) 10+ years of development effort Actively supported Powers Mono Extremely few edge incompatibilities
  • 32. Questions? F# Programming http://en.wikibooks.org/wiki/F_Sharp_Programming A Course of F# Study http://jackfoxy.com/a-course-of-fsharp-study A directory of useful pages http://fsharpforfunandprofit.com/site-contents Learning F#

Notes de l'éditeur

  1. Bibliograhy and sandbox projects of all sample code.multi-paradigm language
  2. Strongly type external data or computing resources dynamicallyDemo freebase type providerDemo R type provider
  3. Let&apos;s take the example of a Multiway Tree. Many kinds of documents can assume this form, HTML, XML, JSON docs, for example. We could model the sequences represented here with any linear data structure. Let&apos;s say it&apos;s Vector for arguments sake, and let&apos;s say the task at hand is to do a breadth first traversal.
  4. Enter the Vector. Indexed lookup and update are pretty close to constant time, O(log32n) if you are keeping score, construction and deconstruction at the end of the sequence, more in line with how humans normally think of extending a linear sequence. You would probably construct days of observed weather this way, for instance.Steffen Forkmann’s implementation of Vector from Clojure. It implements a hash array mapped trie internally. It’s very fast, gives you essentially all the functionality of F# Array, with the added qualities of persistence and the ability to grow and shrink efficiently at the end of the sequence. Vector is probably the most versatile and performant purely functional structure for covering most of your needs involving eager evaluation since it includes indexed lookup and update.
  5. Demo in CrockSolution w/ FsEye parsing into an eager rose tree
  6. Demo in CrockSolution w/ FsEye parsing into an eager rose tree
  7. …and that last line is just to prevent a compiler warning.
  8. Monad Laws:Left identity:return a &gt;&gt;= f≡f aRight identity:m&gt;&gt;=return≡mAssociativity:(m &gt;&gt;= f)&gt;&gt;= g≡m &gt;&gt;=(\x -&gt; f x &gt;&gt;= g)Monoid Laws:Closure: Associativity: mappend x (mappend y z)=mappend(mappend x y) zIdentity element: mappendmempty x = x mappend x mempty= xevery monad is an applicative functor, but not conversely
  9. The rec keyword is not required to be tail recursiveGetFiles returns a string[], so bang(!) required yield the entire enumerable
  10. Inverted SQL style from LINQ“content.templateID.Value” because external data is poorly typed (it includes nulls) so it is returned as an Option type
  11. Inverted SQL style from LINQ“content.templateID.Value” because external data is poorly typed (it includes nulls) so it is returned as an Option type
  12. Demo in CrockSolution w/ FsEye
  13. Unquote in TestSandbox
  14. Demo in CrockSolution w/ FsEye
  15. [Charting World Bank data with F#](http://funscript.info/live/worldbank.html)
  16. http://fssnip.net/jQ
  17. Java lib or app you want to use in a .NET app?.NET dll or app you want to use in the JVM?