Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
F# AND THE DLR Richard Minerich Senior Researcher at Bayard Rock  F# MVP of the Year RichardMinerich.com
The tools we use have a profound (and devious!) influence on our thinking habits, and, therefore, on our thinking abilitie...
Problems in Modern Programming <ul><li>Adding functionality to programs is difficult </li></ul><ul><li>Exploring an existi...
F# vs Dynamic F# Dynamic Languages Constructs conform to types and are fixed at runtime Types conform to constructs and ch...
What is F#? <ul><li>F# is a Multi-Paradigm Language </li></ul><ul><ul><li>Functional with Some Type Extensions </li></ul><...
If you love to code, you’ll love F#. Immutable Data Structures Tail Recursion Discriminated Unions Partial Application Fun...
If you hate to code, you’ll love F#
Functional with Types? Functional + Types
F# is great for… <ul><li>Data Processing </li></ul><ul><li>Technical Computing </li></ul><ul><li>Algorithmic Programming <...
And has the tools to support it.
Functional Programming in F# <ul><li>All statements return something </li></ul><ul><li>let  x =  if  (y > 10)  then  10  e...
F# Programming Paradigms <ul><li>Recursion </li></ul><ul><li>Pipelining </li></ul><ul><li>Matching </li></ul><ul><li>Funct...
Recursion and TCO <ul><li>Using functions which call themselves. </li></ul>Function >  let   rec  badfib n =  if  n < 3  t...
Higher Order Functions Pass Functions into Functions Return Functions from Functions Functions and Values are Interchangea...
Lambda Expressions <ul><ul><li>A function doesn’t always have a name. </li></ul></ul>>  let  addTwo = ( fun   x -> x + 2);...
Pipelining <ul><ul><li>Push data through a series of functions. </li></ul></ul>> [1; 2; 3; 4; 5] |> List.map ( fun  x -> x...
Matching <ul><ul><li>A switch statement on steroids.  </li></ul></ul>match  num with | 1 -> &quot;One&quot; | x when x = 2...
Function Composition <ul><li>Combine functions at runtime </li></ul>let  addOne x = x + 1 let  addTwo x = x + 2 let  addTh...
Discriminated Unions <ul><li>A type that can be one of several other types </li></ul>type name | signature name = name | s...
And More! <ul><li>Statically   Resolved Type Parameters </li></ul><ul><li>Special Record Types </li></ul><ul><li>Object Ex...
Try writing some AI http://is.gd/SilverlightAnts
Try F# at  tryfsharp.org
Find Some Functional Friends <ul><li>The Community For F# Online </li></ul><ul><li>www.communityforfsharp.net </li></ul><u...
Read a Book
What is the DLR? <ul><li>The DLR is a layer on top of the CLR </li></ul><ul><ul><li>Designed for dynamic languages </li></...
The DLR is great for… <ul><li>Test Driven Development </li></ul><ul><li>Web Development </li></ul><ul><li>Using Code from ...
Dynamic in C#
DLR Architecture
Metaobject Visualization Users and programs interact with metaobjects, not directly with their backing objects as in C#, V...
Silverlight and the DLR
Embedded Languages in Your App
DLR Books and Resources http://www.silverlight.net/learn/dynamic-languages/ http://is.gd/DLRFAQ
Thank You <ul><li>Slides and code will be available on  RichardMinerich.com  later today. </li></ul><ul><li>[email_address...
Upcoming SlideShare
Loading in …5
×

F# and the DLR

6,231 views

Published on

Dev Day for NSWC Dahlgren

Published in: Technology

F# and the DLR

  1. 1. F# AND THE DLR Richard Minerich Senior Researcher at Bayard Rock F# MVP of the Year RichardMinerich.com
  2. 2. The tools we use have a profound (and devious!) influence on our thinking habits, and, therefore, on our thinking abilities. -- Edsger Dijkstra
  3. 3. Problems in Modern Programming <ul><li>Adding functionality to programs is difficult </li></ul><ul><li>Exploring an existing code base is very difficult </li></ul><ul><li>Architecture is hard </li></ul><ul><li>Multi-threading is very hard </li></ul><ul><li>Algorithms are difficult to both write and read later </li></ul><ul><li>Why? Our Object-Oriented heritage. </li></ul>
  4. 4. 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
  5. 5. What is F#? <ul><li>F# is a Multi-Paradigm Language </li></ul><ul><ul><li>Functional with Some Type Extensions </li></ul></ul><ul><ul><li>Allows for Object Oriented and Imperative Style Code </li></ul></ul><ul><li>F# is Interactive </li></ul><ul><ul><li>Command Line, Compile or Interactive Window </li></ul></ul><ul><li>F# is a .NET CLR Language </li></ul><ul><ul><li>In the box with Visual Studio 2010 </li></ul></ul><ul><ul><li>Native Interop with every other .NET Language </li></ul></ul><ul><li>F# is Open Source </li></ul><ul><ul><li>But maintained and supported by Microsoft </li></ul></ul>
  6. 6. If you love to code, you’ll love F#. Immutable Data Structures Tail Recursion Discriminated Unions Partial Application Function Composition Quotations Computation Expressions Statically Resolved Type Parameters
  7. 7. If you hate to code, you’ll love F#
  8. 8. Functional with Types? Functional + Types
  9. 9. F# is great for… <ul><li>Data Processing </li></ul><ul><li>Technical Computing </li></ul><ul><li>Algorithmic Programming </li></ul><ul><li>Experimenting with Frameworks </li></ul><ul><li>Implementing Critical Processes </li></ul>
  10. 10. And has the tools to support it.
  11. 11. Functional Programming in F# <ul><li>All statements return something </li></ul><ul><li>let x = if (y > 10) then 10 else y </li></ul><ul><li>Everything is immutable by default </li></ul><ul><li>let rootList = [ 1; 2; 3 ] </li></ul><ul><li>rootList @ [ 4 ] </li></ul><ul><li>Chains, instead of discrete statements </li></ul><ul><li>urls |> List.map download |> Async.Parallel </li></ul>
  12. 12. F# Programming Paradigms <ul><li>Recursion </li></ul><ul><li>Pipelining </li></ul><ul><li>Matching </li></ul><ul><li>Function Composition </li></ul><ul><li>Discriminated Unions </li></ul>
  13. 13. Recursion and TCO <ul><li>Using functions which call themselves. </li></ul>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
  14. 14. Higher Order Functions Pass Functions into Functions Return Functions from Functions Functions and Values are Interchangeable > let findBestSort list = if List.length list < 1000 then insertionSort else quickSort;; val findBestSort : 'a list -> ('b list -> 'b list) when 'b : comparison Function Function Value Value Function Function Function Value is a
  15. 15. Lambda Expressions <ul><ul><li>A function doesn’t always have a name. </li></ul></ul>> let addTwo = ( fun x -> x + 2);; val addTwo : int -> int > List.map ( fun x -> x * 2) [1; 2; 3; 4; 5] [2; 4; 6; 8; 10] let value = (fun v -> v) myFunc (fun v -> v) arg
  16. 16. Pipelining <ul><ul><li>Push data through a series of functions. </li></ul></ul>> [1; 2; 3; 4; 5] |> List.map ( fun x -> x * 2) |> List.filter ( fun x -> x % 3 <> 0);; [2; 4; 8; 10] Data function function function |> |> |> lambda lambda
  17. 17. Matching <ul><ul><li>A switch statement on steroids. </li></ul></ul>match num with | 1 -> &quot;One&quot; | x when x = 2 -> &quot;Two&quot; | _ -> &quot;Higher than I can count“ match exact case when | | -> variable with function -> function -> function name | -> function name predicate | active pattern
  18. 18. Function Composition <ul><li>Combine functions at runtime </li></ul>let addOne x = x + 1 let addTwo x = x + 2 let addThree x = x + 3 let addSix = addOne >> addTwo >> addThree ‘ a -> ‘b ‘ b -> ‘c ‘ a -> ‘c >> =
  19. 19. Discriminated Unions <ul><li>A type that can be one of several other types </li></ul>type name | signature name = name | signature type Option<'a> = | Some of 'a | None let printOutput opt = match opt with | Some (val) -> printfn “%A” val | None -> printfn “No Value” of of
  20. 20. And More! <ul><li>Statically Resolved Type Parameters </li></ul><ul><li>Special Record Types </li></ul><ul><li>Object Expressions </li></ul><ul><li>Comprehensions </li></ul><ul><li>Computation Expressions </li></ul><ul><li>Quotations </li></ul>
  21. 21. Try writing some AI http://is.gd/SilverlightAnts
  22. 22. Try F# at tryfsharp.org
  23. 23. Find Some Functional Friends <ul><li>The Community For F# Online </li></ul><ul><li>www.communityforfsharp.net </li></ul><ul><li>The NYC F# User Group </li></ul><ul><li>www.meetup.com/nyc-fsharp </li></ul><ul><li>The Cambridge F# User Group </li></ul><ul><li>fsug.org </li></ul><ul><li>The San Francisco Bay Area F# User Group </li></ul><ul><li>www.sfsharp.org </li></ul><ul><li>F#unctional Londoners </li></ul><ul><li>www.meetup.com/FSharpLondon </li></ul>
  24. 24. Read a Book
  25. 25. What is the DLR? <ul><li>The DLR is a layer on top of the CLR </li></ul><ul><ul><li>Designed for dynamic languages </li></ul></ul><ul><ul><li>Enables interop with running CLR programs and .NET libraries </li></ul></ul><ul><li>Compatible Implementations </li></ul><ul><ul><li>Python, Ruby, Javascript, and Scheme </li></ul></ul><ul><li>It’s Fast </li></ul><ul><ul><li>IronPython is about 2x the speed of Python </li></ul></ul><ul><li>The Languages are Open Source </li></ul><ul><ul><li>Community maintained and not directly supported </li></ul></ul>
  26. 26. The DLR is great for… <ul><li>Test Driven Development </li></ul><ul><li>Web Development </li></ul><ul><li>Using Code from Existing Dynamic Programs </li></ul><ul><li>Writing your own Language </li></ul><ul><li>Embedding in Applications </li></ul>
  27. 27. Dynamic in C#
  28. 28. DLR Architecture
  29. 29. Metaobject Visualization Users and programs interact with metaobjects, not directly with their backing objects as in C#, VB.NET or F#. control create invoke
  30. 30. Silverlight and the DLR
  31. 31. Embedded Languages in Your App
  32. 32. DLR Books and Resources http://www.silverlight.net/learn/dynamic-languages/ http://is.gd/DLRFAQ
  33. 33. Thank You <ul><li>Slides and code will be available on RichardMinerich.com later today. </li></ul><ul><li>[email_address] </li></ul>

×