Your SlideShare is downloading. ×
0
仕事で使うF#
仕事で使うF#
仕事で使うF#
仕事で使うF#
仕事で使うF#
仕事で使うF#
仕事で使うF#
仕事で使うF#
仕事で使うF#
仕事で使うF#
仕事で使うF#
仕事で使うF#
仕事で使うF#
仕事で使うF#
仕事で使うF#
仕事で使うF#
仕事で使うF#
仕事で使うF#
仕事で使うF#
仕事で使うF#
仕事で使うF#
仕事で使うF#
仕事で使うF#
仕事で使うF#
仕事で使うF#
仕事で使うF#
仕事で使うF#
仕事で使うF#
仕事で使うF#
仕事で使うF#
仕事で使うF#
仕事で使うF#
仕事で使うF#
仕事で使うF#
仕事で使うF#
仕事で使うF#
仕事で使うF#
仕事で使うF#
仕事で使うF#
仕事で使うF#
仕事で使うF#
仕事で使うF#
仕事で使うF#
仕事で使うF#
仕事で使うF#
仕事で使うF#
仕事で使うF#
仕事で使うF#
仕事で使うF#
仕事で使うF#
仕事で使うF#
仕事で使うF#
仕事で使うF#
仕事で使うF#
仕事で使うF#
仕事で使うF#
仕事で使うF#
仕事で使うF#
仕事で使うF#
仕事で使うF#
仕事で使うF#
仕事で使うF#
仕事で使うF#
仕事で使うF#
仕事で使うF#
仕事で使うF#
仕事で使うF#
仕事で使うF#
仕事で使うF#
仕事で使うF#
仕事で使うF#
仕事で使うF#
仕事で使うF#
仕事で使うF#
仕事で使うF#
仕事で使うF#
仕事で使うF#
仕事で使うF#
仕事で使うF#
仕事で使うF#
仕事で使うF#
仕事で使うF#
仕事で使うF#
仕事で使うF#
仕事で使うF#
仕事で使うF#
仕事で使うF#
仕事で使うF#
仕事で使うF#
仕事で使うF#
仕事で使うF#
仕事で使うF#
仕事で使うF#
仕事で使うF#
仕事で使うF#
仕事で使うF#
仕事で使うF#
仕事で使うF#
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

仕事で使うF#

10,671

Published on

Published in: Technology
2 Comments
18 Likes
Statistics
Notes
No Downloads
Views
Total Views
10,671
On Slideshare
0
From Embeds
0
Number of Embeds
8
Actions
Shares
0
Downloads
27
Comments
2
Likes
18
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. F# bleis-tiftAugust 28, 2011
  • 2. F# F#NParsec FParsec
  • 3. F#
  • 4. F#OCaml.NET Framework
  • 5. F#
  • 6. F#cons
  • 7. 1 3[1; 2; 3][1..3]1::2::3::[]1::2::[3][ 1 2 3 ]
  • 8. cons
  • 9. cons
  • 10. cons
  • 11. cons
  • 12. cons
  • 13. cons
  • 14. let xs = [2..10]let ys = 1::xs
  • 15. int string int * string
  • 16. 1let x, y = 10, 20printfn "%A" (x, y) // => (10, 20) 2let (x, y) as tpl = 1, 2printfn "%A" tpl // => (1, 2)printfn "%A" (x, y) // => (1, 2)printfn "(%d, %d)" x y // => (1, 2)
  • 17. let [x; y] as lst = [1; 2]printfn "%A" lst // => [1; 2]printfn "%A" [x; y] // => [1; 2]printfn "[%d; %d]" x y // => [1; 2]warning FS0025: ’[_;_;_]’
  • 18. 1
  • 19. 1
  • 20. 1
  • 21. 2(2, "hoge") // int * string//[2; "hoge"][box 1; box "hoge"] // obj list
  • 22. 2
  • 23. // ,let p = " ", 21type Person = { Name: string Age: int}let p = { Name = " "; Age = 21 } 4
  • 24. F#type Person(name: string, age: int) = member this.Name = name member this.Age = agelet p = Person(" ", 21)type Person = { Name: string; Age: int }let p = { Name = " "; Age = 21 }
  • 25. type Person(name: string, age: int) = member x.Name = name member x.Age = agelet f p = p.Nameerror FS0072:
  • 26. type Person = { Name: string; Age: int }let f p = p.Nametype Person = {Name: string; Age: int;}val f : Person -> string
  • 27. ( )
  • 28. (enum)
  • 29. HtmlElem
  • 30. C#public abstract class HtmlElem {}public class Heading : HtmlElem { public int Level { get; private set; } public string Text { get; private set; } public Heading(int level, string txt) { Level = level; Text = txt; } }public class Text : HtmlElem { public string Text { get; private set; } public Text(string txt) { Text = txt; } }public class HorizontalLine : HtmlElem {}
  • 31. F#type HtmlElem =| Text of string| Heading of int * string| HorizontalLine
  • 32. EqualsGetHashCodeMake static analyzers happy== !=ToString
  • 33. sprintf ”%A”
  • 34. F#F# C#
  • 35. HtmlElem HTMLtype HtmlElem =| Heading of int * string| Text of string| HorizontalLinelet toHtmlStr elem = let h lv s = sprintf "<h%d>%s</h%d>" lv s lv match elem with | Heading(level, txt) -> h level txt | Text txt -> "<p>" + txt + "</p>" | HorizontalLine -> "<hr/>" match
  • 36. let add = function| 0, y -> y| x, 0 -> x| x, y -> x + y function
  • 37. match functionmatchlet add tpl = match tpl with | x, y -> x + yfunctionlet add = function| x, y -> x + y
  • 38. type t = { Tag: int; Value: int }let value { Value = v } = v
  • 39. matchmatchlet add tpl = match tpl with | x, y -> x + yfunctionlet add = function| x, y -> x + ylet add (x, y) = x + y
  • 40. Persontype Name = { FirstName: string LastName: string}type Person = { Name: Name; Age: int }let f x = let { Name = { FirstName = fn } } = x fn
  • 41. F#
  • 42. Maybetype MaybeBuilder() = member this.Bind(x, f) = x |> Option.bind f member this.Return(x) = Some xlet maybe = MaybeBuilder()let plus db = maybe { let! x = db |> Map.tryFind "x" let! y = db |> Map.tryFind "y" return x + y}
  • 43. Map-Reduce ( )fold reducefold
  • 44. fold reducefold reduce
  • 45. F#fold reduce> List.fold;;val it : ((’a -> ’b -> ’a) -> ’a -> ’b list -> ’a) = <fun:clo@1>> List.reduce;;val it : ((’a -> ’a -> ’a) -> ’a list -> ’a) = <fun:clo@2-1>foldreduce list list
  • 46. fold
  • 47. fold
  • 48. fold
  • 49. fold
  • 50. foldfoldsumforallmapfilter
  • 51. foldfoldsumforallmapfilter
  • 52. fold sumsumlet sum xs = List.fold (+) 0 xs
  • 53. fold forallforalllet forall p xs = xs |> List.fold (fun acc x -> acc && (p x)) trueexists
  • 54. fold mapmaplet map f xs = ([], xs) ||> List.fold (fun acc x -> acc @ [f x] )
  • 55. fold filterfilterlet filter p xs = ([], xs) ||> List.fold begin acc x -> if p x then acc @ [x] else acc end
  • 56. foldfold fold( unfold) fold
  • 57. F#
  • 58. F#F# .NET
  • 59. F# F#.NET Framework
  • 60. .NET Framework 2.0 .NET Framework F#
  • 61. .NET Framework F# .NET Framework2.0 Runtime .NET Framework2.0 LINQ F # List.NET Framework 2.0 F#
  • 62. .NET Framework 4.0 F# TDDBC Tokyo 1.6 C# ( ) KeyValueTime.cs 42 SystemClock.cs 30 TddbcKeyValueStore.cs 67 F# ( ) KeyValueStore.fs 48C# 139 F# 48
  • 63. .NET Framework 4.0 F# TDDBC Tokyo 1.6 C# ( ) KeyValueTimeTest.cs 141 SystemClockTest.cs 34 TddbcKeyValueStoreTest.cs 346 ( ) F# ( ) KeyValueStore.fs 170C# 521 F# 170
  • 64. .NET Framework.NET Framework F# 2.0 C# F#
  • 65. F#.NET F# option
  • 66. F# C#VB
  • 67. .NETC# VB
  • 68. F# list F# dll array seq
  • 69. staticNewHoge Tag IsHoge F#
  • 70. module Hogelet plus10 = ((+)10) Hoge.plus10 FSharp.Core.FSharpFunc FSharp.Core.dll
  • 71. NParsec FParsec
  • 72. yacc lex yacc lex
  • 73. BNF
  • 74. parsecJParsecNParsecFParsecscala.util.parsingBoost.Spirit
  • 75. NParsecparsec .NETC# C# JavaScanner
  • 76. FParsecparsec .NETF#
  • 77. NParsec FParsec
  • 78. NParsecvar lazyexpr = new Parser<double>[1];var plazyexpr = Parsers.Lazy<double>(() => lazyexpr[0]);var pterm = plazyexpr.Between(popen, pclose) | pnum;var pexpr = ...lazyexpr[0] = pexpr;
  • 79. FParseclet pexpr, exprref = createParserForwardedToRef()let pterm = pexpr |> between popen pclose <|> pnumdo exprref := ...
  • 80. F# 10 C# 54 C# Visitor
  • 81. C#F#
  • 82. NParsec Bindreturn Parsers.Return(...)FParsec
  • 83. NParsec
  • 84. F# FParsec F#

×