際際滷

際際滷Share a Scribd company logo
Design Pattern In Functional Language覦-蠖:豢螳覦-
覈谿1.  語2.F#3. Design Pattern
 語LISPCommon Lisp, Scheme, ClojureMLSML, nML, Ocaml, F#Etc.Haskell, Erlang
 語企 (lambda calculus)f(x) = x+10(了x.x+10)(了x.x+10) 32 = 32 + 10 = 42(了op.了x.(op x x)) (+) 21 = (了x.((+) x x)) 21 = (+) 21 21 = 42覿 螻(side-effect) ろ 碁 殊 .  語企 覿螻手  .
 語伎蠏 (Recursion)覿覲螳(Immutable Value)螻谿  (High-Order Function)襯 る  豢襦 (Type Inference)ML襯 語
F#HistoryF# 1.0.12005, SDK For VS2003OCaml .NET朱F# 2.02010, VS2010 First Class Language.NET Language
F# BasicF# InteractiveInterpreterInteractive DevelopmentF# TutorialVS2010  Tutorial Project <demo>
F# Syntaxlet 螳 let x = 42let z : string = nulllet F x y = x + ylet F (x,y) = x + y
F# Syntaxfun覓企() let nums = [1; 2; 3;]let odds =List.filter (fun x -> x%2 = 1) numslet oddsSquare =    List.map (fun x -> x * x)        (List.filter (fun x-> x%2 = 1 ) nums)
F# Syntax|>危 一一.let odds =nums    |> List.filter (fun x -> x%2 = 1)let oddsSquare =nums    |> List.filter (fun x -> x%2 = 1)    |> List.map (fun x -> x*x)覲蟇 蟇 螳讌襷 麹 螳煙 譴.
F# SyntaxDiscriminated Uniontype Shape =    | Rect of Point * Point    | Ellipse of Point * Point    | Comp of Shape * Shape
F# SyntaxPattern Matchlet AreaOf shape =    match shape with    | Rect(pf, pt) -> rectArea(pf,pt)    | Ellipse(pf,pt) -> ellipseArea(pf,pt)    | Comp(Rect(p1,p2), Rect(p3,p4))        when isNested(p3,p4,p1,p2)        -> rectArea(p1,p2)    | Comp(s1,s2) ->        let area1 = shapeArea(s1)        let area2 = shapeArea(s2)        area1 + area2  (intersectArea(s1,s2))
Design PatternStrategy PatternCommand PatternComposite PatternDecorate Pattern
Strategy Pattern
Composite Pattern
Command Pattern
Decorate Pattern
谿瑚襭http://www.functional-programming.net/Head First Design Patternshttp://oreilly.com/catalog/9780596007126

More Related Content

Design Pattern In Functional Language