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

Scalaをはじめる α

Scalaをはじめる α

1a679952cdf455ecd6a15cbde7ae80d5?s=128

Tomohiko Himura

June 06, 2015
Tweet

Transcript

  1. 4DBMBΛ͸͡ΊΔЋ -5ۦಈ։ൃ

  2. ͻΉΒͱ΋ͻ͜ +BWBΘ͔ΒΜ

  3. ݄ͷ͍ͭʔͱ https://twitter.com/eielh/status/601729855122608132

  4. ݄ͷ͍ͭʔͱ https://twitter.com/eielh/status/601729855122608132 ܅ͷঠ͸ྫྷ͍ͨ

  5. ·࡙͍ͩͯͳ͍

  6. 4DBMBΛ͸͡ΊΔ͜ͱʹͨ͠

  7. Πϯετʔϧ

  8. IUUQTTQFBLFSEFDLDPNUBLBIJSPIB[JNFUFGBMTFHVBO TIVYJOHQVSPHVSBNJOHVKJBPTIJ TMJEF

  9. IUUQTTQFBLFSEFDLDPNUBLBIJSPIB[JNFUFGBMTFHVBO TIVYJOHQVSPHVSBNJOHVKJBPTIJ TMJEF

  10. )FMMP 8PSME

  11. ΘΜΒ͍ͳʔɻ $ scala -e 'println(“Hello, Z”)' Hello, Z

  12. ର࿩͔Μ͖ΐʔɻ $ scala > println(“Hello, Z”) Hello, Z

  13. ϑΝΠϧʹॻ͘ɻ $ cat hello_world.scala println(“Hello, Z”) $ scala hello_world.scala Hello,

    Z
  14. ͜Μͺ͍Δͯ͠ɻ $ cat HelloCompile.scala object HelloCompile { def main(args: Array[String])

    = println(“Hello, Z”) } $ scalac HelloCompile.scala $ scala HelloCompile Hello, Z
  15. +"7"ͳΒɻ DBU)FMMP+BWBKBWB QVCMJDDMBTT)FMMP\ QVCMJDTUBUJDWPJENBJO 4USJOH<>BSHT \ 4ZTUFNPVUQSJOUMO ʠ)FMMP ;ʡ 

    ^ ^
  16. EFGNBJOΛ͔͖ͨ͘ͳ͍ɻ $ cat HelloNoMain.scala object HelloNoMain extends App { println(“Hello,

    Z”) }
  17. EFGNBJOΛ͔͖ͨ͘ͳ͍ɻ $ cat HelloNoMain.scala object HelloNoMain extends App { println(“Hello,

    Z”) } ୹͍
  18. ֎෦ϥΠϒϥϦΛ࢖͏

  19. ࣮༻తͳ΀Ζ͙ΒΈΜ͙ɻ ֎෦ϥΠϒϥϦͷར༻Λ͍ͨ͠ +"3ϑΝΠϧͬͯ΍ͭͩ

  20. IUUQTFBSDINBWFOPSH

  21. None
  22. TDBMB[Λ͔ͭͬͯΈΔɻ $ scala -version Scala code runner version 2.11.6 --

    Copyright 2002-2013, LAMP/EPFL $ curl -O https://repo1.maven.org/maven2/org/scalaz/ scalaz-core_2.11/7.1.2/scalaz-core_2.11-7.1.2.jar $ scala -cp scalaz-core_2.11-7.1.2.jar > import scalaz.Scalaz._ val hello = (str: String) => "Hello, " + str val z = (str: Option[String]) => str.getOrElse("Z") (hello <<< z)(None) // => "Hello, Z” (hello <<< z)(Some(“World”)) // => “Hello, World”
  23. TDBMB[Λ͔ͭͬͯΈΔɻ $ scala -version Scala code runner version 2.11.6 --

    Copyright 2002-2013, LAMP/EPFL $ curl -O https://repo1.maven.org/maven2/org/scalaz/ scalaz-core_2.11/7.1.2/scalaz-core_2.11-7.1.2.jar $ scala -cp scalaz-core_2.11-7.1.2.jar > import scalaz.Scalaz._ val hello = (str: String) => "Hello, " + str val z = (str: Option[String]) => str.getOrElse("Z") (hello <<< z)(None) // => "Hello, Z” (hello <<< z)(Some(“World”)) // => “Hello, World”
  24. ͜Μͺ͍Δͯ͠ΈΔɻ $ cat HelloZ.scala import scalaz.Scalaz._ class Hello extends App

    { val hello = (str: String) => "Hello, " + str val z = (str: Option[String]) => str.getOrElse("Z") println((hello <<< z)(args.headOption)) } $ scalac -cp scalaz-core_2.11-7.1.2.jar HelloZ.scala $ scala -cp scalaz-core_2.11-7.1.2.jar:. HelloZ Hello, Z $ scala -cp scalaz-core_2.11-7.1.2.jar:. HelloZ World Hello, World
  25. ͜Μͺ͍Δͯ͠ΈΔɻ $ cat HelloZ.scala import scalaz.Scalaz._ class Hello extends App

    { val hello = (str: String) => "Hello, " + str val z = (str: Option[String]) => str.getOrElse("Z") println((hello <<< z)(args.headOption)) } $ scalac -cp scalaz-core_2.11-7.1.2.jar HelloZ.scala $ scala -cp scalaz-core_2.11-7.1.2.jar:. HelloZ Hello, Z $ scala -cp scalaz-core_2.11-7.1.2.jar:. HelloZ World Hello, World
  26. KBWBίϚϯυͰɻ DVSM0IUUQTSFQPNBWFOPSHNBWFOPSHTDBMBMBOH TDBMBMJCSBSZTDBMBMJCSBSZKBS KBWBDMBTTQBUIa TDBMB[DPSF@KBSTDBMBMJCSBSZKBSa )FMMP; )FMMP ;

  27. ϥΠϒϥϦͱ͔ ࣗಈͰ؅ཧͯ͠ཉ͍͠

  28. TCU ͢Ϳͨ Λ࢖͏

  29. ͍Μ͢ͱʔΔ .BD ɻ CSFXJOTUBMMTCU

  30. CVJMETCUΛͭ͘Δɻ DBUCVJMETCU MJCSBSZ%FQFOEFODJFT PSHTDBMB[TDBMB[DPSF

  31. TCUDPOTPMF TCUDPOTPMF JNQPSUTDBMB[4DBMB[@ WBMIFMMP TUS4USJOH )FMMP  TUS WBM[ TUS0QUJPO<4USJOH>

    TUSHFU0S&MTF ;   IFMMP[ /POF
  32. TCUSVO.BJO TCUSVO.BJO)FMMP; )FMMP ; TCUSVO.BJO)FMMP;8PSME )FMMP 8PSME

  33. TCU +"3͸উखʹͻͬͺ͖ͯͯ͘ΕΔ ίϯύΠϧ΋উखʹͯ͘͠ΕΔ UBSHFUσΟϨΫτϦʹ੒Ռ෺ +"3͸_JWZDBDIFʹ

  34. ·ͱΊ

  35. ·ͱΊ TDBMB͸γϯϓϧΒ͍͠ TCU͸ඞਢΞΠςϜΒ͍͠ +"3ʹݻΊΔͱ͍͍Β͍͠