f# and the dlr
DESCRIPTION
Dev Day for NSWC DahlgrenTRANSCRIPT
![Page 1: F# and the DLR](https://reader036.vdocuments.site/reader036/viewer/2022081502/554ebe8fb4c905de468b499f/html5/thumbnails/1.jpg)
F# AND THE DLRRichard Minerich
Senior Researcher at Bayard Rock F# MVP of the Year
RichardMinerich.com
![Page 2: F# and the DLR](https://reader036.vdocuments.site/reader036/viewer/2022081502/554ebe8fb4c905de468b499f/html5/thumbnails/2.jpg)
The tools we use have a profound (and devious!) influence on our thinking habits, and, therefore, on our thinking abilities.
-- Edsger Dijkstra
![Page 3: F# and the DLR](https://reader036.vdocuments.site/reader036/viewer/2022081502/554ebe8fb4c905de468b499f/html5/thumbnails/3.jpg)
Problems in Modern Programming Adding functionality to programs is difficult Exploring an existing code base is very
difficult Architecture is hard Multi-threading is very hard Algorithms are difficult to both write and read
later
Why? Our Object-Oriented heritage.
![Page 4: F# and the DLR](https://reader036.vdocuments.site/reader036/viewer/2022081502/554ebe8fb4c905de468b499f/html5/thumbnails/4.jpg)
F# vs Dynamic
F# Dynamic Languages
Constructs conform to types and are fixed at runtime
Types conform to constructs and change at runtime
Data is immutable by default Generally data is mutable by default
Protection from many kinds of mistakes
No protection, even from typos
Native interop with existing .NET Programs and Libraries
Some work required for interop, but it’s not difficult
Somewhat difficult to learn Very easy to learn
![Page 5: F# and the DLR](https://reader036.vdocuments.site/reader036/viewer/2022081502/554ebe8fb4c905de468b499f/html5/thumbnails/5.jpg)
What is F#?
F# is a Multi-Paradigm Language Functional with Some Type Extensions Allows for Object Oriented and Imperative
Style Code F# is Interactive
Command Line, Compile or Interactive Window F# is a .NET CLR Language
In the box with Visual Studio 2010 Native Interop with every other .NET Language
F# is Open Source But maintained and supported by Microsoft
![Page 6: F# and the DLR](https://reader036.vdocuments.site/reader036/viewer/2022081502/554ebe8fb4c905de468b499f/html5/thumbnails/6.jpg)
If you love to code, you’ll love F#.Immutable Data Structures
Tail RecursionDiscriminated Unions
Partial Application
Function Composition
QuotationsComputation Expressions
Statically Resolved Type Parameters
![Page 7: F# and the DLR](https://reader036.vdocuments.site/reader036/viewer/2022081502/554ebe8fb4c905de468b499f/html5/thumbnails/7.jpg)
If you hate to code, you’ll love F#
![Page 8: F# and the DLR](https://reader036.vdocuments.site/reader036/viewer/2022081502/554ebe8fb4c905de468b499f/html5/thumbnails/8.jpg)
Functional with Types?
Functional + Types
![Page 9: F# and the DLR](https://reader036.vdocuments.site/reader036/viewer/2022081502/554ebe8fb4c905de468b499f/html5/thumbnails/9.jpg)
F# is great for…
Data Processing Technical Computing Algorithmic Programming Experimenting with Frameworks Implementing Critical Processes
![Page 10: F# and the DLR](https://reader036.vdocuments.site/reader036/viewer/2022081502/554ebe8fb4c905de468b499f/html5/thumbnails/10.jpg)
And has the tools to support it.
![Page 11: F# and the DLR](https://reader036.vdocuments.site/reader036/viewer/2022081502/554ebe8fb4c905de468b499f/html5/thumbnails/11.jpg)
Functional Programming in F# All statements return somethinglet x = if (y > 10) then 10 else y
Everything is immutable by defaultlet rootList = [ 1; 2; 3 ]
rootList @ [ 4 ]
Chains, instead of discrete statementsurls |> List.map download |> Async.Parallel
![Page 12: F# and the DLR](https://reader036.vdocuments.site/reader036/viewer/2022081502/554ebe8fb4c905de468b499f/html5/thumbnails/12.jpg)
F# Programming Paradigms
Recursion Pipelining Matching Function Composition Discriminated Unions
![Page 13: F# and the DLR](https://reader036.vdocuments.site/reader036/viewer/2022081502/554ebe8fb4c905de468b499f/html5/thumbnails/13.jpg)
Recursion and TCO
Using functions which call themselves.
Function
> let rec badfib n = if n < 3 then 1 else badfib (n - 1) + badfib (n - 2);;val badfib : int -> int
> let rec fib n1 n2 c = if c = 1 then n2 else fib n2 (n1 + n2) (c - 1);;val fib: int -> int -> int -> int
![Page 14: F# and the DLR](https://reader036.vdocuments.site/reader036/viewer/2022081502/554ebe8fb4c905de468b499f/html5/thumbnails/14.jpg)
Pipelining
Push data through a series of functions.
Data
function
function
function
|>
|>
|> lambda
lambda
> [1; 2; 3; 4; 5]|> List.map (fun x -> x * 2)|> List.filter (fun x -> x % 3 <> 0);;[2; 4; 8; 10]
![Page 15: F# and the DLR](https://reader036.vdocuments.site/reader036/viewer/2022081502/554ebe8fb4c905de468b499f/html5/thumbnails/15.jpg)
Matching
A switch statement on steroids.
match num with| 1 -> "One"| x when x = 2 -> "Two"| _ -> "Higher than I can count“
matchexact case
when
|
|
->
variable
with
function
-> function
-> function
name
| -> function
name
predicate
|active pattern
![Page 16: F# and the DLR](https://reader036.vdocuments.site/reader036/viewer/2022081502/554ebe8fb4c905de468b499f/html5/thumbnails/16.jpg)
Function Composition
Combine functions at runtime
‘a -> ‘b ‘b -> ‘c ‘a -> ‘c>>
=
let addOne x = x + 1let addTwo x = x + 2let addThree x = x + 3let addSix = addOne >> addTwo >> addThree
![Page 17: F# and the DLR](https://reader036.vdocuments.site/reader036/viewer/2022081502/554ebe8fb4c905de468b499f/html5/thumbnails/17.jpg)
Discriminated Unions
A type that can be one of several other types
typenam
e|
signature
name
=
name
|signatur
e
type Option<'a> = | Some of 'a | None
let printOutput opt = match opt with | Some (val) -> printfn “%A” val | None -> printfn “No Value”
of
of
![Page 18: F# and the DLR](https://reader036.vdocuments.site/reader036/viewer/2022081502/554ebe8fb4c905de468b499f/html5/thumbnails/18.jpg)
And More!
Statically Resolved Type Parameters Special Record Types Object Expressions Comprehensions Computation Expressions Quotations
![Page 19: F# and the DLR](https://reader036.vdocuments.site/reader036/viewer/2022081502/554ebe8fb4c905de468b499f/html5/thumbnails/19.jpg)
Try writing some AI
http://is.gd/SilverlightAnts
![Page 20: F# and the DLR](https://reader036.vdocuments.site/reader036/viewer/2022081502/554ebe8fb4c905de468b499f/html5/thumbnails/20.jpg)
Try F# at tryfsharp.org
![Page 21: F# and the DLR](https://reader036.vdocuments.site/reader036/viewer/2022081502/554ebe8fb4c905de468b499f/html5/thumbnails/21.jpg)
Find Some Functional Friends
The Community For F# Onlinewww.communityforfsharp.net
The NYC F# User Groupwww.meetup.com/nyc-fsharp
The Cambridge F# User Groupfsug.org
The San Francisco Bay Area F# User Groupwww.sfsharp.org
F#unctional Londonerswww.meetup.com/FSharpLondon
![Page 22: F# and the DLR](https://reader036.vdocuments.site/reader036/viewer/2022081502/554ebe8fb4c905de468b499f/html5/thumbnails/22.jpg)
Read a Book
![Page 23: F# and the DLR](https://reader036.vdocuments.site/reader036/viewer/2022081502/554ebe8fb4c905de468b499f/html5/thumbnails/23.jpg)
What is the DLR?
The DLR is a layer on top of the CLR Designed for dynamic languages Enables interop with running CLR programs and
.NET libraries Compatible Implementations
Python, Ruby, Javascript, and Scheme It’s Fast
IronPython is about 2x the speed of Python The Languages are Open Source
Community maintained and not directly supported
![Page 24: F# and the DLR](https://reader036.vdocuments.site/reader036/viewer/2022081502/554ebe8fb4c905de468b499f/html5/thumbnails/24.jpg)
The DLR is great for…
Test Driven Development Web Development Using Code from Existing Dynamic
Programs Writing your own Language Embedding in Applications
![Page 25: F# and the DLR](https://reader036.vdocuments.site/reader036/viewer/2022081502/554ebe8fb4c905de468b499f/html5/thumbnails/25.jpg)
Dynamic in C#
![Page 26: F# and the DLR](https://reader036.vdocuments.site/reader036/viewer/2022081502/554ebe8fb4c905de468b499f/html5/thumbnails/26.jpg)
DLR Architecture
![Page 27: F# and the DLR](https://reader036.vdocuments.site/reader036/viewer/2022081502/554ebe8fb4c905de468b499f/html5/thumbnails/27.jpg)
Metaobject Visualization
Users and programs interact with metaobjects, not directly with their backing objects as in C#, VB.NET or F#.
control
createinvoke
![Page 28: F# and the DLR](https://reader036.vdocuments.site/reader036/viewer/2022081502/554ebe8fb4c905de468b499f/html5/thumbnails/28.jpg)
Silverlight and the DLR
![Page 29: F# and the DLR](https://reader036.vdocuments.site/reader036/viewer/2022081502/554ebe8fb4c905de468b499f/html5/thumbnails/29.jpg)
Embedded Languages in Your App
![Page 30: F# and the DLR](https://reader036.vdocuments.site/reader036/viewer/2022081502/554ebe8fb4c905de468b499f/html5/thumbnails/30.jpg)
DLR Books and Resources
http://www.silverlight.net/learn/dynamic-languages/
http://is.gd/DLRFAQ