Functional Programming - PowerPoint PPT Presentation

About This Presentation
Title:

Functional Programming

Description:

Functional Programming Theoretical foundation Church s -calculus expressions and evaluation rules Characteristics Single assignment variables (pure FP) – PowerPoint PPT presentation

Number of Views:41
Avg rating:3.0/5.0
Slides: 13
Provided by: Nen77
Category:

less

Transcript and Presenter's Notes

Title: Functional Programming


1
Functional Programming
  • Theoretical foundation
  • Churchs ?-calculus
  • expressions and evaluation rules
  • Characteristics
  • Single assignment variables (pure FP)
  • Recursion
  • Rule-based and pattern matching (ML, Haskell, F)
  • High-order functions
  • Lazy evaluation (Haskell)
  • Meta-programming (Scheme)

2
F
  • A hybrid language
  • ML-like functional programming
  • Iimperative programming
  • OOP
  • Scripting
  • Runs on the .NET platform
  • It is possible to use any .NET library from F
  • It is possible to use F library from other .NET
    languages such as C
  • Available for free
  • Works with Visual Studio
  • Standalone fsharp interpreter fsi

3
F vs. Prolog
  • Common characteristics
  • Repetition via recursion
  • High-order
  • Garbage collection
  • Differences
  • Strongly typed vs. dynamically typed
  • Functional vs. relational
  • Prolog supports unification and backtracking

4
Types
  • int -- 123, -10
  • float -- 122.123, 0.23e-10
  • bool -- true, false
  • char -- a
  • string -- abc
  • list -- 123, 123, 1_at_23
  • array -- 123
  • tuple -- ("abc",1,true)
  • union -- type MyBool True False

5
Operators
  • , -, , /,
  • , ,not
  • , ltgt, lt, gt, lt, gt

6
let
  • let x 123
  • let f x y xy
  • let f (x,y) xy
  • let rec f n if n 0 then 1 else n(f n-1)

7
Pattern Matching
let rec len lst match lst with -gt 0
_lst1 -gt 1len lst1
8
Tail Recursion
let rec len1 ac lst match lst with
-gt ac (_lstr) -gt len1 (ac1) lstr let
len lst len1 0 lst
9
Unions
type SExp O S of Sexp let rec sum x y
match x with O -gt y S x1 -gt S(sum
x1 y)
10
Unions (Cont.)
type TreeInt Void Leaf of int
Node of intTreeIntTreeInt   let rec count tree
match tree with Void -gt 0 Leaf(_)
-gt 1 Node(_,left,right) -gt 1 (count left)
(count right)  
11
High-order Functions
let succ fun x -gt x1 List.map succ
123 List.map (fun x -gt x1) 123
12
map and fold
let rec map f lst match lst with
-gt (car cdr) -gt (f car)(map f
cdr)   let rec fold f lst acc match lst
with -gt acc (car cdr) -gt f car
(fold f cdr acc)   let rec foldl f lst acc
match lst with -gt acc (car
cdr) -gt foldl f cdr (f car acc)
Write a Comment
User Comments (0)
About PowerShow.com