# Function therory

• View
478

0

Tags:

Embed Size (px)

DESCRIPTION

### Text of Function therory

• 1. F#
function theory

2. F#
type inference
3. //Brackets aren't mandatory:
let f(x,y) = x+y
let f x y= x+y
4. //Function type:
let I x = x
//x: 'a
//I: 'a -> 'a
5. //Example 2:
let K x y = x
//x: 'a
//y: 'b
//K: 'a -> 'b -> 'a
6. //Partial application
let constHi = K "Hello"
let hi = constHi 123
val constHi : (int -> string)
//hi : string ="Hello"
7. //Example 3:
let S x y z = x(z)(y(z))
//x:f(ab)
//x:a -> b -> c
//z:a
//y:a -> b
S x y z: (a -> b -> c) -> (a -> b) -> a -> c
8. //Exercise: What are these functions?
val it :
(('a -> 'b) -> 'a list -> 'b list)
val it :
(('a -> 'b -> 'a) -> 'a -> 'b list -> 'a)
val it : ('a * 'b -> 'a)
9. f(g(x))
F#
function composition
10. //function composition
letcombinefgx=g(f(x))
Letcombine fgx=(f>>g)x
//f:'a -> 'b
//g:'b -> 'c
//x:'a
combine f g x: (a -> b) -> (b -> c) -> a -> c
11. //You can remove the parameter from the last one!
letcombinefg=(f>>g)
// combine: ('a -> 'b) ->
('b -> 'c) ->
('a -> 'c)
12. result: generic abstraction whitout re-ference to concretetypes
lethandle=(save>>validate>>send)
13. F#
14. thought behind LINQ

15. three types of operations
1.
3.
'a -> M
M
16. typical example
2.
M M
3.
M ('b -> 'a -> 'b) -> 'b
17. F#
combinators
18. S- K- I- combinators
Like we started:
I x = x
K x y = x
S x y z =
x z (y z)
19. y-combinator
f(x) when x=f?
f(f) = fandf=f(f)
f(g) = g(f(g))
Y = S (K (S I I)) (S (S (K S) K) (K (S I I)))
http://en.wikipedia.org/wiki/SKI_combinator_calculus
http://en.wikipedia.org/wiki/Fixed_point_combinator
http://community.bartdesmet.net/blogs/bart/archive/2009/08/17/mis-using-c-4-0-dynamic-type-free-lambda-calculus-church-numerals-and-more.aspx
http://channel9.msdn.com/Shows/Going+Deep/Bart-De-Smet-MinLINQ-The-Essence-of-LINQ
http://www.meetup.com/FSharpHelsinki/messages/boards/forum/1395955

Recommended

Documents
Documents
Documents
Documents
Documents
Documents
Documents
Technology
Documents
Documents
Documents
Documents