Haskell Foundations

Download Haskell Foundations

Post on 08-May-2015

2.418 views

Category:

Education

3 download

Embed Size (px)

DESCRIPTION

Chinese (zh-tw) Haskell Fundamentals

TRANSCRIPT

<ul><li>1. Haskell (Beginning)Lambda Calculus Haskell Lambda Calculus (Typed) Haskell (Basics) (Subtitle) edward@tc.program.com.tw (Bibliography) October 22, 20081 / 30 </li></ul> <p>2. Haskell Outline (Beginning)1 (Beginning) Lambda Calculus Lambda2 Lambda Calculus Calculus (Typed)Haskell 3 Lambda Calculus (Typed) (Basics) (Subtitle) 4 Haskell (Basics) (Bibliography)5 (Subtitle) 6 (Bibliography) 2 / 30 3. Haskell Leibniz (Beginning)Lambda Calculus1 Lambda Frege Russell Calculus (Typed) Haskell (Basics)2 (Subtitle) (Bibliography) Entscheidungsproblem /Entquot;S2IdUNsp6bl@m/ ()3 / 30 4. Haskell Entscheidungsproblem (Beginning)Lambda Calculus Church Turing Lambda Calculus (Typed) Lambda calculusAlonzo Church 1936 Haskell (Basics) Turing machinesAlan Turing 1936 7 (Subtitle) (Bibliography) Turing 4 / 30 5. HaskellTuring machines (Beginning)Lambda Calculus Lambda Calculus (Typed)Haskell (Basics) (Subtitle) Figure: Turing Machine 1 (Bibliography) Von Neumann Turing machine Fortran Pascal Turing machine 1 http://en.wikipedia.org/wiki/Turing machine gallery5 / 30 6. HaskellLambda calculus (Beginning)Lambda Calculus Alonzo Church 1936 lambda calculus Lambda Calculus (Typed) Haskell Brookes Curry Alonzo Church 1934 Haskell 1940 lambda calculus (Basics) Miranda ML Haskell (Subtitle) lambda calculus (Bibliography) Lisp Reduction machines 6 / 30 7. Haskell (Beginning) Lambda calculus Lambda LambdaTerm (lambda ) Calculus lambda term Lambda x Calculus (Typed) x Haskell (Basics) lambda term lambda term x x (Subtitle) (x x ) y z (Bibliography) . lambda term lambda term x. x (lambda abstraction lambda )x y . x y 7 / 30 8. Haskell (Beginning)Lambda x. M lambda term M x Calculus (bound) Lambda x ((x. x + 1)y ) z Calculus (Typed) x Haskell (Basics) (free variable) lambda lambda (Subtitle) lambda (Bibliography)(closed term) lambda lambda (open term)8 / 30 9. Haskell Combinator (Beginning)Lambda Calculus lambda combinator Lambda Calculus (Typed) Identity combinator I x. x Haskell K xy . x (Basics) K xy . y (Subtitle) S xyz. x z (y z) (Bibliography) Fixpoint combinator Y f . (x. f (x x)) (x. f (x x)) F . F (Y F ) = Y F 9 / 30 10. Haskell Reduction () (Beginning)Lambda Calculus E E Lambda Reduction PE Calculus (Typed)P Haskell (Basics) E [P] E [P ] (Subtitle) (v .M)N (Bibliography) (xy . s x y ) u v s x y [x := u, y := v ] s u v10 / 30 11. Haskell (Full Reduction) (Beginning)Lambda Calculus (full reduction) Lambda Calculus (Typed)Haskell (Basics) id(id(z.id z)) id(z.id z) (Subtitle) id(z.z) (Bibliography) z.z 11 / 30 12. Haskell (Normal Order Strategy Reduction) (Beginning)Lambda Calculus (normal order strategy) Lambda Calculus (Typed) Haskell (Basics) (Subtitle) id(id(z.id z)) id(z.id z) (Bibliography) z.id z z.z 12 / 30 13. HaskellCall By Name (Beginning) Call by name lambda Lambda( lambda ) Calculus Lambda Calculus (Typed)Haskell id(id(z.id z)) id(z.id z) (Basics) z.id z (Subtitle) (Bibliography) Call by name lazy evaluation Haskell lazy evaluation lambda 13 / 30 14. HaskellCall By Value (Beginning) Call by value Lambda Calculus Lambda Calculus (Typed)Haskell (Basics)id(id(z.id z)) id(z.id z) (Subtitle) z.id z (Bibliography) Call by value strict evaluation (bfg . if b then f else g ) b f g call-by-value call-by-name 14 / 30 15. Haskell (Beginning)Lambda Calculus 1 true K false K Lambda2 [M, N] z. z M N z M N Calculus (Typed)if B then M else N Haskell [M, N] true = M (Basics) [M, N] false = N (Subtitle) Proof. (Bibliography)[M, N] true (z. z M N) (xy . x)= z M N[z := (xy . x)] (xy . x) M N= x[x := M, y := N] M 15 / 30 16. Haskell() (Beginning)3 n n Lambda Calculus0 =I n + 1 = [false, n ] Lambda Calculus 4 (Typed) S+ n = n + 1 Haskell (Basics)P n + 1 = n (Subtitle) Zero 0 = true Zero n + 1 = false (Bibliography)Proof.S+ x. [false, x]P x. x falseZero x. x true16 / 30 17. Haskell() (Beginning)Lambda Calculus LambdaAdd(0, y) = y Calculus (Typed) Add(x+1, y) = 1+Add(x, y) Haskell lambda (Basics) Add x y = if Zero x then y else S+ (Add (P x) y ) (Subtitle) Y combinator (Bibliography)Add Y(axy . if Zero x then y else S+ (a (P x) y ))17 / 30 18. Haskell H. B. Curry 1934 1958 (Beginning) 1972 lambda Lambda Calculusterm Lambda T Calculus (Typed) lambda term M Haskell T (Basics) (Subtitle) M: N : (Bibliography) MN : x:...M:x. M : 18 / 30 19. HaskellHaskell (Beginning)Lambda Calculus 1 1987 Haskell Brookes Curry Lambda Calculus 2 Haskell 98 (Typed)Haskell 3 Haskell (Basics)4 standard prelude (Subtitle)5 http://haskell.org 2 (Bibliography)2http://haskell.org/ghc GHC ( Haskell 98 ) Windows Linux Solaris Mac OS 19 / 30 20. Haskell (Value) (Beginning)Lambda Calculus Haskell 5 :: Integer Lambda Calculus K :: Char (Typed) False :: Bool Haskell [3,2,1] :: [Integer] (Basics) (b, True) :: (Char, Bool) (Subtitle) id :: a -&gt; a id x = x (Bibliography) (Typing):: Type 20 / 30 21. Haskell Bool (Beginning) Char Lambda String Char Calculus Hello [H,e,l,l,o] Lambda Calculus Int 231 231 1 (Typed) Integer Haskell (Basics) Float (Subtitle) List list [Int] list (Bibliography) Tuple tuple (Int, Int) tuple -&gt; Int -&gt; Int 21 / 30 22. Haskell (Beginning)Lambda Calculus Lambda Calculus data Type-constructor = Data-constructor s (Typed) Haskell (Basics)data Color = Red | Orange | Yellow (Subtitle) | Green | Blue | Indigo | Violet data constructor (Bibliography) data Point a = Pt a a22 / 30 23. Haskell (Beginning) data Tree a = Leaf a | Branch (Tree a) (Tree a) Lambda Calculus flatten ::Tree a -&gt; [a] flatten (Leaf x) = [x] Lambda Calculus flatten (Branch x y) = flatten x ++ flatten y (Typed) Haskell (Basics)1 test.hs 2 GHC (Subtitle)3 test.hs ghci (Bibliography) 4 GHCi :l test.hs 5 GHCi flatten (Branch (Branch (Leaf a) (Leaf b)) (Leaf c)) 6 GHCi :q GHCi 23 / 30 24. Haskell (Beginning)Lambda Calculus (++) :: [a] -&gt; [a] -&gt; [a] Lambda[]++ys = ys Calculus (Typed) (x:xs)++ys = x:(xs++ys) Haskell data Tree a = Leaf a | Branch (Tree a) (Tree a) (Basics) flatten :: Tree a -&gt; [a] (Subtitle) flatten (Leaf x) = [x] (Bibliography)flatten (Branch x y) = flatten x ++ flatten y O 2 24 / 30 25. Haskell ++ (Beginning)Lambda (accumulating argument) ++ Calculus Lambda Calculus atten t acc = atten t ++ acc (Typed)Haskell atten (Leaf x) acc (Basics) = { atten } (Subtitle)atten (Leaf x) ++ acc = { atten } (Bibliography)[x] ++ acc= { ++ }x:acc25 / 30 26. Haskell ++ () (Beginning)Lambda atten (Tree x y) acc Calculus= { atten } Lambda atten (Tree x y) ++ acc Calculus (Typed)= { atten } Haskell (atten x ++ atten y) ++ acc (Basics)= { ++ } (Subtitle) atten x ++ (atten y ++ acc) = { x } (Bibliography)atten x (atten y ++ acc)= { y }atten x (atten y acc)26 / 30 27. Haskell ++ () (Beginning)Lambda Calculus Lambda Calculus (Typed)Haskell atten :: Tree a -&gt; [a] -&gt; [a] (Basics) atten (Leaf x) acc = x:acc (Subtitle) atten (Tree x y) acc = atten x (atten y acc) (Bibliography)27 / 30 28. Haskell (Beginning) Lambda lambda calculus Calculus Turing machines. Lambda Calculus Lambda calculus (Typed) Haskell (Basics) Lambda (Subtitle) Lambda calculus (Bibliography) call-by-name call-by-value Haskell Haskell data 28 / 30 29. Haskell (Beginning)Lambda Calculus Lambda Calculus (Typed) Haskell (standard prelude) Haskell (Basics) lambda Haskell (Subtitle) Haskell (Bibliography) 29 / 30 30. Haskell (Beginning)Lambda Calculus1 Benjamin C. Pierce. Types and Programming Language. MIT, 2002. 2 Graham Hutton. Programming in Haskell. Cambridge, 2007. Lambda Calculus 3 Henk Barendregt and Erik Barendsen. Introduction to Lambda (Typed)Calculus. [Online] Available: Haskell ftp://ftp.cs.kun.nl/pub/CompMath.Found/lambda.pdf (Oct, 2008). (Basics)4 Hal Daum III. Yet another Haskell tutorial. [Online] Available:e (Subtitle) http://www.cs.utah.edu/ hal/docs/daume02yaht.pdf (Oct, 2008). 5 Paul Hudak, John Peterson, and Joseph Fasel. A gentle introduction (Bibliography)to Haskell: Version 98. [Online] Available:http://www.haskell.org/tutorial/ (Oct, 2008). 30 / 30 </p>