Académique Documents
Professionnel Documents
Culture Documents
The F# Path to
Relaxation
Language Design, Tools, Platforms, Community, Ecosystem,
Exosystem, Openness, Cross-platform,
Don Syme, F# Community Contributor
A starting position.
The great disputes of computer science
should be struggled with
They are chances to make a better, simpler,
more relaxed world as much as create
opposing camps
Functiona
l
Interop
Then (2003)
Functional languages were isolated, noninteroperable, using their own VMs. Interop
standards like C-calls, COM, CORBA, XML were a
mess for language-integration.
Functiona
l
Interop
Enterpris
e
Opennes
s
F# 4.0
True shift to cross-platform open
engineering
Long laundry list of language items
Normalized core library
Type providers more powerful
Better debugging, tooling, performance
Enterpris
e
Relaxation Achieved
Enterprise Quality + Openness +
Community + Tooling +
Ecosystem + Evolution Path
=
Goodness
Opennes
s
Functiona
l
Objects
Then (2003)
In the 1990s functional languages were historically
anti-OO
Even today any mention of objects gives some people an
urrgghhh reaction.
Modern Compiler Implementation with Standard ML - Chapter 14,
Object Oriented Programming
F# - Objects + Functional
type Vector2D (dx:double, dy:double) =
let d2 = dx*dx+dy*dy
Inputs to object
construction
member v.DX = dx
Object internals
member v.DY = dy
Exported properties
Exported method
Objectstype ObjectType(args) =
Object Expressions
{ new IObject with
member x.Prop1 = expr
member x.Meth1 args = expr }
{ new Object() with
member x.Prop1 = expr
interface IObject with
member x.Meth1 args = expr
interface IWidget with
member x.Meth1 args = expr }
Functional
Expressio No null
noriented
O
b
j
e
c
t
s
Multiple
Args =
Tuples
Closure
and
Capture
Firstclass
Values
Currying
void
(unit)
Object
Types
Subtypin
g
Dotnotation
Relatively Graceful
Method
Overlodi
ng
Degradation
(some type
annotations
needed)
Relatively Graceful
Degradation
(some
type annotations
needed)
Inheritan
ce
HM Type
Inference
Some
combinations
outlawed
for
sanity
350,000
lines of C# OO
by offshore team
30,000
Zero
Functiona
l
Objects
SpecFlow (C#
TickFlow (F#)
Pattern
Matching
Abstractio
n
Active Patterns in F#
These tags are
active recognizer
labels
llet
et((||Rect
Rect||)) ((x:
x:com
com pl
plex)
ex)== ((x.
x.Real
Real,,x.
x.IImm agi
aginary)
nary)
llet
et((||Pol
Polar|
ar|)
)((x:
x:com
com pl
plex)
ex)== ((x.
x.MM agni
agnittude
ude ,,x.
x.Phase)
Phase)
ll
et
ll
et
mmmmm
ul
ul
Vi
Vi
aRect
aPol
ar
(c1
Rect
((c1
Pol
ar(
(ar,
ai)
tt)
h1)
(Rect
))((Pol
(br,
ar(
bi
r2,
)) t
=
let
ul
Vi
aPol
aRect
ar
c2
c2
==r1,
=
et
ul
Vi
aPol
ar
Pol
ar(
r1,
h1)
Pol
ar(
r2,
th2)
h2)))==
et
ul
Vi
aPol
ar
c1
c2
Cr
eat
eat
eRect
ePol
ar(
(c2
ar*br
r1*r2,
tth1+
*bi,tt
ai
h2)
*br + bi*ar)
mmCCmr
at
at
ch
ch
c1,
c1,
c2
w
iitthh
ithai
The use of active
r
eat
ePol
ar(
r1*r2,
h1+
h2)
at
ch
c1,
c2
ww
recognizer labels
||Pol
| Rect
ar(
(ar,
tth1)
ai),,,Pol
Rect
(br,
r2,
bi
tth2)
) ->Pol
ar(r1,
r1,
h1)
Polar(
ar(
r2,
h2)
->
>
CCr
C
reat
ePol
eRect
ar(
(ar*brtt
-h1+
ai*bi
tth2)
, ai*br +implicitly
bi*ar) select
reat
eat
ePol
ar(r1*r2,
r1*r2,
h1+
h2)
and apply the
function
((||Rect
Polar|
|))
module BasicPatterns =
let (|Value|_|) (e:FSharpExpr) = ...
let (|Const|_|) (e:FSharpExpr) = ...
let (|TypeLambda|_|) (e:FSharpExpr) = ...
let (|Lambda|_|) (e:FSharpExpr) = ...
let (|Application|_|) (e:FSharpExpr) = ...
let (|IfThenElse|_|) (e:FSharpExpr) = ...
let (|Let|_|) (e:FSharpExpr) = ...
let (|LetRec|_|) (e:FSharpExpr) = ...
let (|NewRecord|_|) (e:FSharpExpr) = ...
let (|NewUnionCase|_|) (e:FSharpExpr) = ...
let (|NewTuple|_|) (e:FSharpExpr) = ...
let (|TupleGet|_|) (e:FSharpExpr) = ...
Pattern
Matching
Abstractio
n
Relaxation Achieved
An extremely useful mechanism that greatly expands the
utility of pattern matching in the language
Dont leave home without them
Code
In one large
company, ~500
people work on
tooling for this
Data
and 5000+
people work on
tooling for this
2012 2013
6,432 10,537
Paradigm Locator
Options
http://fsharp.github.io/FSharp.Data/images/csv.gif
http://fsharp.github.io/FSharp.Data/images/wb.gif
Segoe UI Light
types
SQL #1
1/22/16
67
SQL #2
1/22/16
68
CSV
1/22/16
69
JSON
1/22/16
70
XML
1/22/16
71
Hadoop/Hive
1/22/16
72
Web APIs
1/22/16
73
Entity Graphs
1/22/16
74
WSDL
1/22/16
75
1/22/16
76
data.Automotive.``Automobile Models``
data.Automotive.``Automobile Models``.Individuals.``Porsche 911``
Every stable
entity can
get a unique
type
Code
Data
Relaxation Achieved
F# Type Providers have been a hugely successful feature their
range of useful application is enormous. They bring data and
typed programming into synthesis like no other feature around
Sync
Async
Numbers
Numberswith Units
GPU
CPU
http://fsharp.org/use/gpu
Whats Ahead?
Well, for me, many areas of tension in upstack
language design have been resolved
But there are still some areas that bug me...
REPL
Distributio
n and
Scale
http://m-brace.net
Rows
Columns
In Conclusion!
Funct
ional
Code
Obje
cts
Asyn
c
Sync
Data
Open
Ente
rpris
e
Thank you!!
Questions?
2012 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries.
The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a
commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS
PRESENTATION.