An Introduction to F# Sushant aboutdev.com

Slides:



Advertisements
Similar presentations
Introduction to Compilation of Functional Languages Wanhe Zhang Computing and Software Department McMaster University 16 th, March, 2004.
Advertisements

Introduction to OCaml Slides prepared by Matt Gruskin Some material borrowed from the CIS 500 lecture notes.
1 Scheme and Functional Programming Aaron Bloomfield CS 415 Fall 2005.
Chapter 5: Abstraction, parameterization, and qualification Xinming (Simon) Ou CIS 505: Programming Languages Kansas State University Fall
Programming Languages and Paradigms
Tail Recursion. Problems with Recursion Recursion is generally favored over iteration in Scheme and many other languages – It’s elegant, minimal, can.
Recap 1.Programmer enters expression 2.ML checks if expression is “well-typed” Using a precise set of rules, ML tries to find a unique type for the expression.
1 Programming Languages (CS 550) Lecture Summary Functional Programming and Operational Semantics for Scheme Jeremy R. Johnson.
Functional Programming. Pure Functional Programming Computation is largely performed by applying functions to values. The value of an expression depends.
Map and Fold Building Powerful Abstractions. Hello. I’m Zach, one of Sorin’s students.
By Neng-Fa Zhou Functional Programming 4 Theoretical foundation –Church’s -calculus expressions and evaluation rules 4 Characteristics –Single assignment.
Chapter 15 Other Functional Languages. Copyright © 2007 Addison-Wesley. All rights reserved. Functional Languages Scheme and LISP have a simple syntax.
Copyright © 2006 The McGraw-Hill Companies, Inc. Programming Languages 2nd edition Tucker and Noonan Chapter 14 Functional Programming It is better to.
CSC321: Programming Languages14-1 Programming Languages Tucker and Noonan Chapter 14: Functional Programming 14.1 Functions and the Lambda Calculus 14.2.
7/2/20151 Programming Languages and Compilers (CS 421) Elsa L Gunter 2112 SC, UIUC Based in part on slides by Mattox.
OCaml The PL for the discerning hacker.. Hello. I’m Zach, one of Sorin’s students.
An introduction to F# Bogdan Brinzarea-Iamandi Banca Romaneasca 22 February 2010.
CSE-321 Programming Languages Introduction to Functional Programming (Part II) POSTECH March 13, 2006 박성우.
1 COMP313A Functional Programming (1). 2 Main Differences with Imperative Languages Say more about what is computed as opposed to how Pure functional.
Λ => Scheme for Rubyists. Scheme History Authors: Guy Steele and Gerald Sussman Structure and Interpretation of Computer Programs (SICP) by Abelson &
10/14/20151 Programming Languages and Compilers (CS 421) Grigore Rosu 2110 SC, UIUC Slides by Elsa Gunter, based.
Robert Vitolo CS474.  Branched off of ML (metalanguage)  Developed at Microsoft, available as part of the Visual Studio 2010 software package, integrated.
Programming Languages and Paradigms Imperative Programming.
Functional Programming With examples in F#. Pure Functional Programming Functional programming involves evaluating expressions rather than executing commands.
Going Functional Primož Gabrijelčič. Functional programming.
Compiling Functional Programs Mooly Sagiv Chapter 7
TIVDM2Functional Programming Language Concepts 1 Concepts from Functional Programming Languages Peter Gorm Larsen.
PROGRAMMING LANGUAGES: PROLOG, CLOJURE, F# Jared Wheeler.
CMSC 330: Organization of Programming Languages Maps and Folds Anonymous Functions.
CSE 130 : Spring 2011 Programming Languages Ranjit Jhala UC San Diego Lecture 6: Higher-Order Functions.
1 Programming Languages (CS 550) Lecture 4 Summary Functional Programming and Operational Semantics for Scheme Jeremy R. Johnson.
Recursion A recursive definition is one which uses the word or concept being defined in the definition itself Example: “A computer is a machine.
Functional Programming IN NON-FUNCTIONAL LANGUAGES.
Spring 2008Programming Development Techniques 1 Topic 5.5 Higher Order Procedures (This goes back and picks up section 1.3 and then sections in Chapter.
1 CSC103: Introduction to Computer and Programming Lecture No 16.
Functional Programming. Some Functional Languages Lisp Scheme - a dialect of Lisp Haskell Miranda.
Haskell Introduction CSCE 314 Spring CSCE 314 – Programming Studio Historical Background 1930s: Alonzo Church develops the lambda calculus, a simple.
3/8/20161 Programming Languages and Compilers (CS 421) Reza Zamani Based in part on slides by Mattox Beckman, as updated.
Cs7120 (Prasad)L1-FP-HOF1 Functional Programming Basics Correctness > Clarity > Efficiency.
Cs776 (Prasad)L2HOF1 Higher-Order Functions. cs776 (Prasad)L2HOF2 Higher-Order Functions A function that takes a function as argument and/or returns a.
1 Introduction to Functional Programming in Racket CS 270 Math Foundations of CS Jeremy Johnson.
Introduction to Functional Programming Part 1 – The Basic Concepts Winter Young
Functional Programming
Functional Programming
Chapter 8: Recursion Data Structures in Java: From Abstract Data Types to the Java Collections Framework by Simon Gray.
Programming Languages and Compilers (CS 421)
Lesson #6 Modular Programming and Functions.
Lesson #6 Modular Programming and Functions.
Programming Languages and Compilers (CS 421)
CMSC 330: Organization of Programming Languages
Introduction to Functional Programming in Racket
Fundamentals of Functional Programming Languages
Lesson #6 Modular Programming and Functions.
Important Concepts from Clojure
Important Concepts from Clojure
Control Flow Chapter 6.
Functional Programming
Programming Languages and Compilers (CS 421)
Procedural vs Functional Style
CSE 341 Section 5 Winter 2018.
Abstraction and Repetition
Madhusudan Parthasarathy
341 midterm review Xinrong Zhao Autumn 2018.
Introduction to Functional Programming in Racket
Lesson #6 Modular Programming and Functions.
CSE-321 Programming Languages Introduction to Functional Programming
Important Concepts from Clojure
Programming Languages and Compilers (CS 421)
Abstraction and Repetition
Review Previously in: Lots of language features: functions, lists, records, tuples, variants, pattern matching Today: No new language features New idioms.
Presentation transcript:

An Introduction to F# Sushant aboutdev.com

Why learn F#?

Overview  Tour of F# in Visual Studio 2011  Fundamentals of F#  Functional Programming  Examples

F# in Visual Studio 2011 DEMO

Fundamentals of F#

SignatureNameDescriptionExample Unit () int, floatConcrete Type10, 6.04 ‘a, ‘bGeneric Type ‘a -> ‘bFunction Typefun x -> x + 1 ‘a * ‘bTuple TypeOrdered collection of values (1, 2), (“ten”, “soup”) ‘a listList TypeList of values[1; 2; 3], [1.. 3] ‘a optionOption TypeOptional valueSome(3), None Core Types

 Default -> anonymous module  Nest Modules  Namespace Modules & Namespaces

 Pass results of first function to second  Benefit  Chain functions together  Type inference Pipe Forward [1.. 10] |> List.map (fun x -> x * x) |> List.iter (printfn "%i")

 Series of rules that will execute if a pattern matches the input.  Switch on Steroids Pattern Matching

 Type  1 of a set of possible values  Used for complex data structures Discriminated Unions

Functional Programming

What is Functional Programming? A function is a rule that associates to each x from some set X of values, a unique y from another set Y of values. If f is the name of the function, y = f ( x ) f : X → Y

Functional programming is a programming paradigm that treats computations as the evaluation of mathematical functions and avoids state and mutable data. [Wikipedia]

 All programs and procedures are functions and clearly distinguish incoming values from outgoing values  There are no variables or assignments – variables are replaced by parameters  There are no loops – replaced by recursive calls  The value of a function depends only on the value of its parameters and not on the order of evaluation or the execution path that led to the call  Functions are first-class values (viewed as values themselves, computed by other functions and can be parameters to functions) [Programming Languages. Kenneth C Louden]

1.First Class Functions 2.Higher Order Functions 3.Pure Functions 4.Recursion / Tail Recursion 5.Currying

1. First Class Functions a) Bind an identifier to a function definition let sqr = fun n -> n * n b) Store functions in data structures let aTuple = (sqr, fun n -> n + n) let aList = [sqr, fun n -> n + n]

2. Higher Order Functions a) Pass function as an argument let data = List.map (fun n -> n * n) [ 1; 2; 3; 4; ] b) Return function as value of function let sqrList = let funSqr = fun lst -> List.map (fun a -> a * a) lst funSqr

3. Pure Functions a)No Side Effects / Referential transparency b)Caching optimizations (memoization) c)No Data Dependency = order of execution is independent and can be parallel (thread-safe)

4. Recursion / Tail Recursion a) Iteration through recursive invocation let rec factorial x = if x <= 1I then 1I else let recResult = factorial (x-1I) let result = x * recResult result b) Tail recursion – Accumulators let factorialTail x = let rec tailRecFact x acc = if x <= 1I then acc else tailRecFact (x-1I) (acc * x) tailRecFact x 1I

5. Currying let add x y = x + y let addToTen = add 10 addToTen 5

Demo 1.Type Provider – Netflix 2.Units of Measure 3.Async / Parallel

Examples – Project Euler

How to Learn F# 1.Programming F# - Chris Smith 2.Beginning F# - Robert Pickering 3.Expert F# - Don Syme videos.html

Giveaway / Raffle 2 e-books