Design Pattern In Functional Language
- 4. 語企 (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) ろ 碁 殊 . 語企 覿螻手 .
- 8. F# Syntaxlet 螳 let x = 42let z : string = nulllet F x y = x + ylet F (x,y) = x + y
- 9. 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)
- 10. 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)覲蟇 蟇 螳讌襷 麹 螳煙 譴.
- 12. 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))