Presentation is loading. Please wait.

Presentation is loading. Please wait.

Robert Vitolo CS474.  Branched off of ML (metalanguage)  Developed at Microsoft, available as part of the Visual Studio 2010 software package, integrated.

Similar presentations


Presentation on theme: "Robert Vitolo CS474.  Branched off of ML (metalanguage)  Developed at Microsoft, available as part of the Visual Studio 2010 software package, integrated."— Presentation transcript:

1 Robert Vitolo CS474

2  Branched off of ML (metalanguage)  Developed at Microsoft, available as part of the Visual Studio 2010 software package, integrated into the.NET environment just as C#, Visual C  Allows for three programming paradigms: Imperative, Object-Oriented, or Functional

3  Modeled on mathematical functions, rooted in lamda calculus  Relatively simple syntax and semantic structure compared to imperative languages that give it high readability.  Uses ‘functions’ that are conceptually similar to math functions, making it a highly appropriate paradigm for representing equations or performing math operations

4  Allows you to quickly evaluate expressions or perform computation on- the-fly

5

6  Data structures make it a fitting language candidate for computation over large sets of data. List (homogeneous data) Tuple (related data) Record (heterogeneous data) Discriminated Unions

7  Purely functional languages do not use mutable data or mutable states, and thus are inherently thread safe – the output value of a function depends entirely on its arguments. List, for example, is a data structure that stores an immutable series of ordered elements as a linked list, all of the same type. F# does allow mutable data if you explicitly define it with a ‘mutable’ keyword i.e. let mutable x = 5.  This frees up the programmer from having to manage complex thread synchronization / locks

8  Problem: Return the square of a range of numbers. Return the squares of 1 to n: [1 2, 2 2 … n 2 ]  In this example, from integers 1 to 10.  Two approaches: C# approach F# approach

9 C# CODEOUTPUT

10 1. Define the function “square” and what it does 2. Define a range of numbers, using a List [brackets] 3. Map the function square to each item in the list -- to each number 123123

11  Using the Task Parallel Library you can create parallel programs in F#. You have access to all of the same.NET functions in C#, including Parallel.For, Parallel LINQ (PLINQ) and Parallel CPU Asyncs  In this example we’ll use PLINQ, which is the best one to use if you want to program in a purely functional manner.

12  Problem: Find the sum for all squares in a range of values in parallel and return the execution time and the sum.  In this example, from integers 1 to 1500.

13 F# CODE AND OUTPUT

14  Think of the execution of this statement in this manner: Take our list of numbers (1 to 1500) and map the squaring function sqr to each item, and return that set of values. Take the set of values and run the function “sum” on that set, and return the answer to ParallelSumOfSquares.

15  Problem: Find the largest value in a list of values in parallel and return that value.  Code:

16  Result:

17  The burning question: Is F# “faster” or “better” than C# ? How about for parallel programming? Answer:  In terms of Productivity?Yes, for many applications  Parallel Programming?Yes, for ease of setup  Execution Time?No


Download ppt "Robert Vitolo CS474.  Branched off of ML (metalanguage)  Developed at Microsoft, available as part of the Visual Studio 2010 software package, integrated."

Similar presentations


Ads by Google