Upgrade to Pro — share decks privately, control downloads, hide ads and more …

入門言語としての F#

2f710cd36766586d2b6210f2a2be2b97?s=47 0918nobita
August 28, 2021

入門言語としての F#

2f710cd36766586d2b6210f2a2be2b97?s=128

0918nobita

August 28, 2021
Tweet

Transcript

  1. ೖ໳ݴޠͱͯ͠ͷ F# ୈ2ճ Fun Fan Fsharpɹkodai (@0918nobita)

  2. ࣗݾ঺հ • ໊લɹদຊ ޾େ ·ͭ΋ͱ ͜͏͍ͩ • Twitterɹ@0918nobita • GitHubɹ0918nobita

    • झຯɿ 
 ϓϩάϥϛϯά 
 DTM (࡞ۂ), ΤϨΩϕʔεԋ૗ 
 Πϥετ੍࡞ • ޷͖ͳϓϩάϥϛϯάݴޠɿ 
 Rust, F#, OCaml, Haskell, Elm, Racket, Scala, FORTH, m4, …etc. Α͘࢖͏ΞΠίϯ 
 (੺Ҫ͸͋ͱ)
  3. ϓϩάϥϛϯάʹ 
 Ͳ͏΍ͬͯೖ໳͠·͔ͨ͠ʁ

  4. ๻ͷϓϩάϥϛϯάͱͷग़ձ͍ ϓνίϯ mk-Ⅱ Ͱ BASIC ݴޠʹೖ໳ (தֶ̍೥ͷࠒʁ) ͱʹ͔͘γϯϓϧͳ໋ྩܕϓϩάϥϛϯάݴޠ 
 


    ίʔυͷݟͨ໨͸… 
 
 FOR I = 1 TO 10 IF I MOD 15 == 0 THEN PRINT "FIZZBUZZ" ELSEIF I MOD 5 == 0 THEN PRINT "BUZZ" ELSEIF I MOD 3 == 0 THEN PRINT "FIZZ" ENDIF NEXT 
 ϥϕϧʹର͢Δ GOTO ͰແݶϧʔϓΛͭ͘Δ 
 GOSUB / RETURN ໋ྩͰαϒϧʔνϯ΋࢖͑Δ औѻઆ໌ॻɿhttps://smileboom.com/special/ptcm2/co_manual/p01.php
  5. ࠓʮϓϩάϥϛϯά ࢝ΊํʯͰάάΔͱ… (1)

  6. ࠓʮϓϩάϥϛϯά ࢝ΊํʯͰάάΔͱ… (2)

  7. ࠓʮϓϩάϥϛϯά ࢝ΊํʯͰάάΔͱ… (3) • స৬ઌΛ୳͍ͯ͠Δਓ޲͚ͷهࣄ (ࣗεΫʔϧ΁ͷ༠ಋ͕ଟ͍) • ด࠯తͳίϛϡχςΟʹ༠ಋ͢ΔɺΠϯϑϧΤϯαʔͷ৘ใ঎ࡐ • ʮϓϩάϥϛϯά

    = WebɾεϚϗΞϓϦ։ൃʯʁʁ • ͦ΋ͦ΋಺༰͕ਖ਼֬͞ʹ͚ܽΔ΋ͷ΋ଟ͍ • ७ਮʹ޷ح৺͔Βϓϩάϥϛϯάʹ৮ΕΑ͏ͱ͍ͯ͠Δਓ޲͚ͷ 
 هࣄ͸΄ͱΜͲώοτ͠ͳ͍
  8. ϓϩάϥϛϯά΁ͷ஫໨౓͕ߴ·ͬͨӨڹͰ 
 ঎ۀతͳଆ໘ͷ͋Δ৘ใʹᷓΕͯ͠·ͬͨ

  9. ࠓʮϓϩάϥϛϯάΛʯڭ͑ΔͳΒ 
 ͲͷݴޠͰڭ͑Δʁ

  10. ……ͦΕ F# ϐολϦ͡Όͳ͍ʁ

  11. ϓνίϯ mk-Ⅱ ͷΑ͔ͬͨͱ͜ΖΛࢥ͍ग़ͯ͠ΈΔ શવ࠳ંͤͣʹ໋ྩܕϓϩάϥϛϯάΛशಘͰ͖ͨ • ʮಈ͘΋ͷ͕खݩʹग़དྷ্͕Δʯ·Ͱͷεςοϓ਺͕গͳ͍ • άϥϑΟοΫɾα΢ϯυɾϘλϯ/ը໘ૢ࡞ܥ API ͷར༻͕؆୯

    • ੒Ռ෺Λڞ༗͢Δ؀ڥ͕੔͍ͬͯͯɺϞνϕҡ࣋ʹͭͳ͕ͬͨ • ωοτͰௐ΂ͨͱ͖ʹϊΠζ (௼Γ/௿඼࣭ͳهࣄ) ͕গͳ͔ͬͨ • ݹͷ BASIC ϓϩάϥϚ͕ผϋʔυͷήʔϜΛҠ২͍ͯͯ͠ɺ 
 ϕςϥϯ৬ਓͷΑ͏Ͱ୯७ʹ͔ͬ͜Α͔ͬͨ
  12. F# ͷೖ໳ݴޠͱͯ͠ͷՄೳੑ (1) • ೖ໳ݴޠͱͯ͠ఆ൪ͳ C, Java, C# ʹൺ΂ͯɺ 


    ୯७ʹιʔείʔυͷλΠϓ਺͕গͳ͍܏޲͕͋Δ 
 (λΠϓϛεͱίϯύΠϧΤϥʔΛ܁Γฦͯ͠࠳ં͢Δ཰͕௿͍) • ߴϨΠϠͷݴޠͳͷͰɺP/Invoke ͱ͔ Re f lection ΛѻΘͳ͍ 
 ୯७ͳϓϩάϥϜͰ͋Ε͹ϙΠϯλͷ஌͕ࣝཁٻ͞Εͳ͍ 
 (࠷ॳ͔ΒϙΠϯλ΍௿ϨΠϠͷ࿩͕བྷΜͰ࠳ં͢ΔͷΛ๷͛Δ)
  13. F# ͷೖ໳ݴޠͱͯ͠ͷՄೳੑ (2) • GtkSharp ౳Λ࢖͑͹ GUI Λ૊ΊΔ 
 →

    ໨ʹݟ͑Δ੒Ռ • ASP.NET 5, Giraffe ౳Λ࢖͑͹ Web ΞϓϦ΋࡞ΕΔ 
 → Web ܥͰ΋εϜʔζʹਐΊΔ • ݱঢ়ɺF# ͰάάΔͱߴΊͷස౓Ͱ 
 ݰਓͷٕज़هࣄ͕ώοτ͢ΔͷͰ஌ࣝΛਂΊΔػձʹܙ·ΕΔ 
 (ྑ͘΋ѱ͘΋ϚΠφʔݴޠ͔ͩΒ…)
  14. F# Λೖ໳ݴޠʹ͢Δ͏͑Ͱͷ໰୊ • ೔ຊޠͰॻ͔ΕͨղઆαΠτ͕·ͩ·ͩগͳ͍ • ࢹ֮తͳ੒Ռ͕ಘΒΕΔΑ͏ͳೖ໳ํ๏͕प஌͞Ε͍ͯͳ͍ • ੒Ռ෺Λެ։͢ΔɾӾཡ͢Δํ๏͕प஌͞Ε͍ͯͳ͍ • ϓϩάϥϛϯάॳֶऀʹدΓఴ͏ελΠϧͷڭࡐ͕গͳ͍

    • Ի੠ܥϥΠϒϥϦͷσϑΝΫτ͕Θ͔Βͳ͍ (ௐࠪෆ଍͔΋ʁ) ·ͩ·ͩࢁੵΈ
  15. ʮͳΒࣗ෼Ͱཧ૝ͷڭࡐΛ࡞Ζ͏ʯ

  16. fs-education ϓϩδΣΫτ ϓϩάϥϛϯάॳֶऀʹɺF# Λ༻͍ͨϓϩάϥϛϯάͷڭࡐΛಧ͚Δ ϓϩδΣΫτ (ؔ࿈ιʔείʔυ͸ OSS ͱͯ͠ݪଇ͢΂ͯެ։)

  17. F# ͰʮԿΛʯ࡞ͬͯ΋Β͏ʁ 
 ໨ʹݟ͑Δ੒Ռ͕͋ͬͨ΄͏͕͍͍

  18. fs-education ͷΧϦΩϡϥϜ (ߏ૝) 1. ؀ڥߏங 2. ڭࡐͷ୳͠ํɾ৘ใϦςϥγʔ 3. ࣜͷධՁɾ໊લଋറɾجຊతͳܕ 4.

    ؔ਺ఆٛͱݺͼग़͠ɾؔ਺ܕ 5. Ϧετܕɾ഑ྻܕɾλϓϧɾ൑ผڞ༻ମ 6. ύλʔϯϚον 7. ܁Γฦ͠ 8. (࣮ફฤ) ਺͋ͯήʔϜͷ࣮૷ 9. ࠶ؼɾ໦ߏ଄σʔλͷ૸ࠪ 10.Option, Result 11. ߴ֊ؔ਺ɾΫϩʔδϟɾܧଓ౉͠ελΠϧ 12. ref, let mutable (ࢀরɾՄมଋറ) 13. ΫϥεɾΠϯλʔϑΣʔεͱεςʔτϚγϯ 14. ϏϧμΫϥεͱίϯϐϡςʔγϣϯࣜ 15. Async, Task ʹΑΔඇಉظॲཧɾseq / lazy Λ׆༻ͨ͠஗ԆධՁ 16. GtkSharp Λ༻͍ͨ GUI ϓϩάϥϛϯά 17. (࣮ફฤ) γϡʔςΟϯάήʔϜͷ࣮૷ 18. ASP.NET 5.0, Giraffe Λ༻͍ͯ Web ΞϓϦέʔγϣϯαʔόΛߏங (+ HTML / CSS / JS) 19. σʔλϕʔεೖ໳ (TODO ΞϓϦͷ࣮૷) 20.(૯·ͱΊ) ΦϯϥΠϯରઓήʔϜͷઃܭɾ࣮૷
  19. F# ։ൃ؀ڥͱͯ͠ԿΛקΊΔʁ 
 Ͱ͖Δ͚ͩϋʔυϧΛ௿͘͢ΔͨΊɺ࠷ॳ͸ۃྗ GUI Ͱ

  20. F# ͷ։ൃ؀ڥͷվળ (1) VS Code + ionide-fsharp ʹΑΔڧྗͳίʔσΟϯάࢧԉ

  21. F# ͷ։ൃ؀ڥͷվળ (2) .NET Interactive Notebooks Ͱ࣮ݱ͢Δշదͳର࿩؀ڥ

  22. F# ͷ։ൃ؀ڥͷվળ (3) Jupyter Notebook ͱͷ࿈ܞ 
 ίϚϯυϥΠϯͰͷಋೖ࡞ۀ͕ඞཁ 
 


    dotnet tool install -g \ 
 —add-source “https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet-tools/nuget/v3/index.json” \ 
 Microsoft.dotnet-interactive # `interactive` dotnet tool ͷΠϯετʔϧ dotnet interactive jupyter install # Jupyter Kernel (C# / F# / PowerShell) ͷΠϯετʔϧ jupyter kernelspec list # Πϯετʔϧ֬ೝ
  23. F# ͷ։ൃ؀ڥͷվળ (4) Jupyter Notebook ͱͷ࿈ܞ

  24. F# ͷ։ൃ؀ڥͷվળ (4) Jupyter Notebook ͱͷ࿈ܞ

  25. .NET Interactive Notebooks & 
 Jupyter Notebook 
 DEMO

  26. fs-education Ͱ͸ 
 .NET Interactive Notebooks Λ 
 ϑϧ׆༻͍ͯ͘͜͠ͱʹ͠·ͨ͠ʂ

  27. fs-education ͷݱঢ় ࣥචɾࣗಈϏϧυ/σϓϩΠ؀ڥͷߏங͕͋Δఔ౓Ͱ͖ͨͷͰɺ 
 ຊจͷࣥචΛ։࢝ͨ͠ F# ੡ϏϧυεΫϦϓτ 
 (Markdown ->

    HTML ม׵ͱ 
 ໨࣍ͷࣗಈੜ੒) ੩తαΠτͷϗεςΟϯάʹར༻ GitHub Actions Work f low push Πϕϯτ ࣗಈσϓϩΠ Markdown ܗࣜͰهࣄΛ؅ཧ
  28. ༨ஊͰ͕͢… ԻͷϥΠϒϥϦΛ F# Ͱ૊ΜͰ͍·͢ https://github.com/0918nobita/fs-examples/tree/main/sound

  29. ॳֶऀʹͱͬͯϓϩάϥϛϯά͕ 
 ָ͍͠΋ͷͱͳΔΑ͏ʹ… fs-education ΁ͷίϯτϦʔϏϡʔτ͸େ׻ܴͰ͢ʂ 
 https://github.com/0918nobita/fs-education

  30. ͝ਗ਼ௌ͋Γ͕ͱ͏͍͟͝·ͨ͠