Function therory

  • View
    478

  • Download
    0

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#
monads
14. thought behind LINQ
list monadIEnumerable
maybe monadNullable

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)))
20. references / links
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://blogs.msdn.com/b/madst/archive/2007/05/11/recursive-lambda-expressions.aspx
http://www.madore.org/~david/programs/unlambda/
http://channel9.msdn.com/Shows/Going+Deep/Brian-Beckman-Dont-fear-the-Monads
http://channel9.msdn.com/Shows/Going+Deep/C9-Lectures-Greg-Meredith-Monadic-Design-Patterns-for-the-Web-Introduction-to-Monads
http://blogs.msdn.com/b/wesdyer/archive/2008/01/11/the-marvels-of-monads.aspx
http://channel9.msdn.com/Shows/Going+Deep/Bart-De-Smet-MinLINQ-The-Essence-of-LINQ
http://ttic.uchicago.edu/~dreyer/course/papers/wadler.pdf
http://www.meetup.com/FSharpHelsinki/messages/boards/forum/1395955