diff --git a/_ja/cheatsheets/index.md b/_ja/cheatsheets/index.md index f34596a8cf..9038a75a42 100644 --- a/_ja/cheatsheets/index.md +++ b/_ja/cheatsheets/index.md @@ -5,7 +5,7 @@ title: Scala Cheatsheet partof: cheatsheet by: Kenji Ohtsuka -about: Thanks to Brendan O'Connor. このチートシートは Scala 構文 のクイックリファレンスとして作成されました。 Licensed by Brendan O'Connor under a CC-BY-SA 3.0 license. +about: Thanks to Brendan O'Connor. このチートシートは Scala 構文 のクイックリファレンスとして作成された。 Licensed by Brendan O'Connor under a CC-BY-SA 3.0 license. language: ja --- diff --git a/_ja/index.md b/_ja/index.md index a19f4f8285..8167613f05 100644 --- a/_ja/index.md +++ b/_ja/index.md @@ -1,13 +1,47 @@ --- -layout: inner-page-documentation +layout: documentation title: ドキュメント language: ja -partof: documentation -discourse: true +more-resources-label: その他のリソース + # Content masthead links -more-resources-label: その他のリソース -sections: + +scala3-sections: + - title: "First steps" + links: + - title: "Scala 3 の新機能" + description: "Scala 3 で追加されたさまざまな新機能の概要" + icon: "fa fa-star" + link: /ja/scala3/new-in-scala3.html + - title: "Scala 3 をはじめる" + description: "あなたのコンピューターに Scala 3 をインストールしてScalaコードを書きはじめよう!" + icon: "fa fa-rocket" + link: /ja/scala3/getting-started.html + - title: "Scala 3 Book" + description: "主要な言語仕様のイントロダクションをオンラインブックで読む" + icon: "fa fa-book" + link: /scala3/book/introduction.html + - title: "More detailed information" + links: + - title: "Migration Guide" + description: "Scala 2 から Scala 3 へ移行するためのガイド" + icon: "fa fa-suitcase" + link: https://scalacenter.github.io/scala-3-migration-guide/ + - title: "Guides" + description: "Scala 3 の言語仕様からピックアップして解説" + icon: "fa fa-map" + link: /ja/scala3/guides.html + - title: "API" + description: "Scala 3 の全バージョンのAPIドキュメント" + icon: "fa fa-file-text" + link: https://dotty.epfl.ch/api/index.html + - title: "Language Reference" + description: "Scala 3 の言語仕様" + icon: "fa fa-book" + link: https://dotty.epfl.ch/docs/reference/overview.html + +scala2-sections: - title: "最初のステップ" links: diff --git a/_ja/scala3/contribute-to-docs.md b/_ja/scala3/contribute-to-docs.md new file mode 100644 index 0000000000..01ca57a37f --- /dev/null +++ b/_ja/scala3/contribute-to-docs.md @@ -0,0 +1,67 @@ +--- +layout: inner-page-documentation +overview-name: "Scala 3 Documentation" +title: Contributing to the Docs +language: ja +scala3: true +--- + +## 概要 +Scala 3 の高品質なドキュメンテーションを作るためのいくつかの試みが目下進行中である。 +特に次のようなドキュメントがある。 + +- Scala 3 book +- Macros tutorial +- Migration guide +- Scala 3 language reference + +ドキュメンテーションの種類に関わらずコミュニティからのコントリビューションを歓迎する。 + + +### コントリビューションの仕方 +さまざまな方法で私たちを支援することができる : +- **ドキュメントのどこかで混乱するところがある** Issue をたてる。 +- **最新の状態を反映していないドキュメントがある** Issue をたてるか、PR をつくる。 +- **タイポの修正やその他ちょっとした文章の改善** PR をつくる。 +- **なにかを新しく追加したり大きな変更を加えたい** 議論できるよう Issue をたてる。 + +通常、ドキュメントプロジェクトのそれぞれには編集・改善用のリンクが含まれている。(このドキュメントについても同様で、目次の領域にある。) また、コントリビューションをはじめるために必要な情報は以下に記載されている。 + +## Scala 3 Book +[Scala 3 Book][scala3-book] は Alvin Alexander 氏 が書いている。 この本は Scala 3 のすべての重要な機能の概説書である。これから Scala を使いはじめる読者を対象にしている。 + +- [Sources](https://github.com/scala/docs.scala-lang/tree/master/_overviews/scala3-book) +- [Issues](https://github.com/scala/docs.scala-lang/issues) + +## Macros Tutorial +[Macros Tutorial](/scala3/guides/macros)は Nicolas Stucki 氏 が書いている。この本では Scala 3 のマクロとそのベストプラクティスについて詳しく説明している。 + +- [Sources](https://github.com/scala/docs.scala-lang/tree/master/_overviews/scala3-macros) +- [Issues](https://github.com/scala/docs.scala-lang/issues) + +## Migration Guide +[Scala 3 Migration Guide](https://scalacenter.github.io/scala-3-migration-guide/) は Scala 2 と Scala 3 の互換性、移行に役立つツールの紹介、そして詳しい移行のガイドを含んだ包括的なドキュメントである。 + +- [Contribution Overview](https://scalacenter.github.io/scala-3-migration-guide/docs/contributing.html) +- [Source](https://github.com/scalacenter/scala-3-migration-guide) +- [Issues](https://github.com/scalacenter/scala-3-migration-guide/issues) + + +## Scala 3 Language Reference +The [Dotty reference](https://dotty.epfl.ch/docs/reference/overview.html) は Scala 3 になる予定である。これにはさまざまな言語仕様に関する公式のプレゼンテーションや技術的情報が含まれている。 + +- [Sources](https://github.com/lampepfl/dotty/tree/master/docs/docs/reference) +- [Issues](https://github.com/lampepfl/dotty/issues) + + +[scala3-book]: {% link _overviews/scala3-book/introduction.md %} + +[best-practices]: {% link _overviews/scala3-macros/best-practices.md %} +[compiletime]: {% link _overviews/scala3-macros/tutorial/compiletime.md %} +[cross-compilation]: https://scalacenter.github.io/scala-3-migration-guide/docs/macros/migration-tutorial.html#cross-building +[inline]: {% link _overviews/scala3-macros/tutorial/inline.md %} +[macros]: {% link _overviews/scala3-macros/tutorial/macros.md %} +[migration-status]: https://scalacenter.github.io/scala-3-migration-guide/docs/macros/macro-libraries.html#macro-libraries +[quotes]: {% link _overviews/scala3-macros/tutorial/quotes.md %} +[tasty]: {% link _overviews/scala3-macros/tutorial/reflection.md %} +[reflection-api]: https://dotty.epfl.ch/api/scala/quoted.html diff --git a/_ja/scala3/getting-started.md b/_ja/scala3/getting-started.md new file mode 100644 index 0000000000..4790cb78ca --- /dev/null +++ b/_ja/scala3/getting-started.md @@ -0,0 +1,251 @@ +--- +layout: singlepage-overview +title: Getting Started with Scala 3 +scala3: true +language: ja +--- + + + +## Try Scala without installing anything + +いますぐ Scala 3 を試してみたいなら ブラウザ上で動作する“Scastie” を使ってみよう。 +_Scastie_ は Scala のコードがどのように動作するか試せるオンラインのプレイグラウンドである。全ての Scala のコンパイラと公開されているライブラリを使うこともできる。 + + +## Scala をインストールする + +Scala をインストールするということはつまり、さまざまなコマンドラインツールやビルドツールをインストールするということである。 +Scala のインストーラツール "Coursier" を使うのが推奨されている。Coursier を使えばインストールが必要なものすべてを自動でインストールできる。 もちろん、手動でそれぞれのツールをインストールすることもできる。最低限 Java、sbt があれば Scala のコードを書き始められる。 + +### Scala インストーラ を使う (推奨) + +Scala インストーラは [Coursier](https://get-coursier.io/docs/cli-overview)という名前のツールで、メインコマンドは`cs`である。 +Coursier はシステムに JVM と Scala のツールがインストールされているかどうか確認する。 + +次の手順に従って Coursier をインストールしてください。 + +
+
+

cs launcherをインストールする手順に従ってインストールし、次のコマンドを実行する。:

+

$ ./cs setup

+
+
+ +JVM の管理に加えて、 `cs setup` コマンドは次のような便利なコマンドラインツールもインストールする。: + +- JDK +- ビルドツール [sbt](https://www.scala-sbt.org) と [mill](https://www.lihaoyi.com/mill) +- [Ammonite](https://ammonite.io), 高機能 REPL +- [scalafmt](https://scalameta.org/scalafmt), the Scala formatter +- [Coursier CLI](https://get-coursier.io/docs/cli-overview), Scala で書かれたアプリケーションをインストールできる +- (**Scala 2.13** 向けの `scala` コマンドと `scalac` コマンド。Scala 3 用ではない。) + + + +`cs setup`を実行したら以下のコマンドで Java, Scala がインストールされているかどうか確認する。 + +```shell +java --version +scala --version +``` + +詳しくは、 [coursier-cli documentation](https://get-coursier.io/docs/cli-overview)を読もう。 + +### ... または、手動でインストールする + +Scala プロジェクトをコンパイル、実行、テストやパッケージングするには次の二つのツールだけで十分である。Java 8 または 11、そして sbt である。 +これらのツールを手動でインストールするには、以下の手順に従ってください。 + +1. Java を [Oracle Java 8](https://www.oracle.com/java/technologies/javase-jdk8-downloads.html), [Oracle Java 11](https://www.oracle.com/java/technologies/javase-jdk11-downloads.html), か [AdoptOpenJDK 8/11](https://adoptopenjdk.net/)からダウンロードする。 Scala/Java の互換性の詳細については [JDK Compatibility](/overviews/jdk-compatibility/overview.html) を参照せよ。 +2. [sbt](https://www.scala-sbt.org/download.html) をインストールする。 + +## sbtで “Hello, world” プロジェクトを作成する + +Scala 3 をインストールする前に、Scala を使ったことがない開発者に向けて sbt を使ってプロジェクトを作成、実行する方法について解説する。 + +もし sbt でプロジェクトを作成する方法を既に知っているなら 「Scala 3 のインストール」 の章まで読み飛ばしていい。 + +コマンドライン、IDE のどちらからでも sbt プロジェクトを作成できる。 + +もし慣れているならコマンドラインツールを使うアプローチを推奨する。 + + +### コマンドラインツールを使う + +sbt は Scala のビルドツールである。 +sbt を使って Scala のコードをコンパイル、実行やテストできる。 + +(ライブラリを公開したり他の様々なタスクを実行することもできる。) + +sbt で新しくプロジェクトを作成するには次の手順に従ってください。: + +1. `cd` コマンドで新しいディレクトリに移動する。 +1. `sbt new scala/hello-world.g8` コマンドを実行する。 +このコマンドを実行すると ['hello-world' template][template-url] を GitHub から pull する。 +また、無視してよい _target_ フォルダを作成する。 +1. ターミナルでアプリケーション名の入力を促されたら `hello-world` と入力する。 + "hello-world"と言う名前のプロジェクトが作成される。 +1. 次のようなファイル、ディレクトリが作成される: + +``` +hello-world/ + project/ (sbt が管理するファイルがここに入ります。) + build.properties + src/main/scala/ (Scala のソースコードはここに書きます。) + Main.scala (プログラムのエントリーポイントです。) + build.sbt (sbt の ビルド定義ファイルです。) +``` +今のところ `src/main/scala` にある `Main.scala` だけ必要である。 + +sbt の詳しいドキュメントは [Scala Book](/scala3/book/scala-tools.html) と sbt 公式 [documentation](https://www.scala-sbt.org/1.x/docs/index.html) にある。 + + +{% comment %} +### With IntelliJ IDEA + +これ以降は読み飛ばしてそのまま [Building a Scala Project with IntelliJ and sbt](/getting-started/intellij-track/building-a-scala-project-with-intellij-and-sbt.html)を見ても問題ない。 +{% endcomment %} + + +## “Hello, world” プロジェクトを開く + +IDE を使ってプロジェクトを開く。 +最も人気なエディタは IntelliJ IDEA と VS Code である。 +どちらも 高度な IDE 機能を提供している。しかし、 [その他のエディタ](https://scalameta.org/metals/docs/editors/overview.html)を使うこともできる。 + +### IntelliJ IDEA を利用する + +1. [IntelliJ Community Edition](https://www.jetbrains.com/idea/download/) をダウンロード、インストールする。 +1. リンク先の手順に従って Scala プラグインをインストールする。 [the instructions on how to install IntelliJ plugins](https://www.jetbrains.com/help/idea/managing-plugins.html) +1. _build.sbt_ ファイルを開いて、 _Open as a project_ を選択する。 + +### VS Code と Metals を利用する + +1. [VS Code](https://code.visualstudio.com/Download) をダウンロードする。 +1. [Marketplace](https://marketplace.visualstudio.com/items?itemName=scalameta.metals) から 拡張機能 Metals をインストールする。 +1. 次に、_build.sbt_ ファイルが置いてあるディレクトリを開いてください。ダイアログが表示されたら _Import build_ をクリックする。 + +>[Metals](https://scalameta.org/metals) は Scala の lauguage server である。Metals は Lauguage Server Protocol を使ってVS Code やその他のエディタ、たとえば[Atom, Sublime Text, and more](https://scalameta.org/metals/docs/editors/overview.html)、で Scala を書くための補助機能を提供している。 +(Metals の仕組みについて詳しく知りたい方は、以下のリンクを参照。 [“Write Scala in VS Code, Vim, Emacs, Atom and Sublime Text with Metals”](https://www.scala-lang.org/2019/04/16/metals.html).) + + + +### ソースコードを見る + +以下の2つのファイルをIDEで開く: + +- _build.sbt_ +- _src/main/scala/Main.scala_ + +次のステップでプロジェクトを起動したとき、_build.sbt_ に書かれた設定が _src/main/scala/Main.scala_ を実行するために使われる。 + + +## “Hello, world” プロジェクトを実行する + +IDEを使ってコードを書くのに特に抵抗がないなら、 _Main.scala_ に書かれたコードをIDEから実行しよう。 + +そうでないなら、次の手順でターミナルからアプリケーションを実行することもできる。 + +1. `cd` コマンドで _hello-world_ に移動する。 +1. `sbt` コマンドを実行してください。sbt console が開く。 +1. `~run` と入力。 + `~` は オプショナルな接頭辞で、これを付けるとファイルを保存するたびに sbt がそのコマンドを実行するので 編集/実行/デバッグのサイクルを高速に回せる。sbt は自身が使うために `target` ディレクトリを生成する。 開発者はこのディレクトリを無視してよい。 + +このプロジェクトを試し終えたら、エンターキーを押し `run` コマンドの実行を停止しよう。 + +`exit`と入力するか `[Ctrl][d]` ショートカットをおすと sbt から出てコマンドプロンプトに戻る。 + +### Scala 3 のインストール + +Scala 3 を始めるには以下のような方法があります。詳しくは[こちら](https://dotty.epfl.ch/)も参照してください。 + +1. sbt をインストールし sbt で`sbt new lampepfl/dotty.g8` を実行して Scala 3 プロジェクトを始めることができる。 +1. 先に説明した通り、`cs setup` コマンドを使って Java、Scala(2.**)の環境をセットアップすることができる。 また、`cs install scala3-compiler`、`cs install scala3-repl`コマンドでそれぞれ Scala 3 のコンパイラ、 Scala 3 の REPL をインストールできる。 +1. Scala 3 のソースを[ここ](https://github.com/lampepfl/dotty/releases)から手動でインストールすることができる。 + +#### sbt を使って Scala 3 プロジェクトをはじめる(オプショナル) + +上の手順で`cs setup` をすでに実行しているなら `sbt`コマンドが使えるようになっているはずである。 以下のコマンドを実行することで Scala 3 のテンプレートプロジェクトを作れる。 +```shell +sbt new lampepfl/dotty.g8 +``` + +Scala 2 とクロスコンパイル可能なプロジェクトテンプレートを利用する場合は以下のコマンドを実行しよう。 + +```shell +sbt new lampepfl/dotty-cross.g8 +``` +#### Coursierを使ってScala 3 用のコンパイラと REPL をインストールする(オプショナル) + +以下では Scala 3 のコンパイラ、REPL と Scala 3 をインストールする手順を説明する。 + +```shell +cs install scala3-compiler +cs install scala3-repl +``` + +インストールしたコンパイラ、REPL は`cs launch ` で実行できる。 +```shell +cs launch scala3-compiler -- Hello.scala +``` + +```shell +cs launch scala3-repl +``` + + + +#### Scala 3 を手動でインストールする(オプショナル) + +Scala 3 はまだリリースされていないので Github から最新のソース(2021/03時点で scala3-3.0.0-RC1 )を直接ダウンロードしてpathを通す。 + +```shell +wget https://github.com/lampepfl/dotty/releases/download/3.0.0-RC1/scala3-3.0.0-RC1.tar.gz +tar -zxvf scala3-3.0.0-RC1.tar.gz +``` + + + + + +## 次のステップ + +Scala 3 を使った 最初の “Hello world” プロジェクトを作れたので、 次のステップに進む。 + +以下の記事をチェックしよう: + +- [The Scala 3 Book](/scala3/book/introduction.html), Scala の主要な機能の導入となる一連の短いレッスンが用意されている。 +- [The migration guide](https://scalacenter.github.io/scala-3-migration-guide/) 既にある Scala 2 で書かれたコードベースを Scala 3 に移行する際に役立つ情報がまとめてある。 + +他の Scala ユーザーと交流したいなら、いくつかのメーリングリストやリアルタイムチャットルームがある。 +これらのリソースのリストや助けを求める場所を探すには、[Scala community page](https://scala-lang.org/community/) をチェックしよう。 + + + + + + + + + + +[template-url]: https://github.com/scala/hello-world.g8 diff --git a/_ja/scala3/guides.md b/_ja/scala3/guides.md new file mode 100644 index 0000000000..df6a0cf240 --- /dev/null +++ b/_ja/scala3/guides.md @@ -0,0 +1,71 @@ +--- +layout: inner-page-parent +title: Scala 3 のガイド +language: ja +scala3: true + + +guides: + - title: "Scala 2 から Scala 3 への移行" + icon: suitcase + url: "https://scalacenter.github.io/scala-3-migration-guide" + description: "Scala 3 との互換性と移行について知っておくべきことすべて" + - title: マクロ + by: Nicolas Stucki + icon: magic + url: "/scala3/guides/macros" + description: "Scala 3 のマクロの書き方に関係する全ての機能をカバーする詳しいチュートリアル" + label-text: feature + - title: TASTyの概要 + by: Alvin Alexander + icon: birthday-cake + url: "/scala3/guides/tasty-overview.html" + description: "Scala のエンドユーザー向けの TASTy のフォーマットの概要" +--- + +
+
+
+
+

概要とガイド

+

+ Scala 3 とその機能についての詳しいガイド +

+
+ {% for overview in page.guides %} +
+
+
+ {% if overview.icon %} +
+
+
+ {% endif %} +

{{ overview.title }}

+
+
+ {% if overview.label-text %}
{{ overview.label-text }}
{% endif %} + {% if overview.by %}
By {{ overview.by }}
{% endif %} + {% if overview.description %}

{{ overview.description }}

{% endif %} + {% if overview.subdocs %} + Contents + + {% endif %} +
+
+ +
+ {% endfor %} +
+
+
+
+
+ + diff --git a/_ja/scala3/index.md b/_ja/scala3/index.md new file mode 100644 index 0000000000..f44799ef9b --- /dev/null +++ b/_ja/scala3/index.md @@ -0,0 +1,44 @@ +--- +layout: inner-page-documentation +title: Documentation for Scala 3 +language: ja +namespace: root +scala3: true +discourse: true +# Content masthead links +more-resources-label: More Resources +sections: + + - title: "First steps" + links: + - title: "Scala 3 の新機能" + description: "Scala 3 で追加されたさまざまな新機能の概要" + icon: "fa fa-star" + link: /ja/scala3/new-in-scala3.html + - title: "入門" + description: "あなたのコンピューターにScala 3 をインストールしてScalaコードを書きはじめよう!" + icon: "fa fa-rocket" + link: /ja/scala3/getting-started.html + - title: "Scala 3 Book" + description: "主要な言語仕様のイントロダクションをオンラインブックで読む" + icon: "fa fa-book" + link: /scala3/book/introduction.html + - title: "More detailed information" + links: + - title: "Migration Guide" + description: "Scala 2 から Scala 3 へ移行するためのガイド" + icon: "fa fa-suitcase" + link: https://scalacenter.github.io/scala-3-migration-guide/ + - title: "Guides" + description: "Scala 3 の言語仕様からピックアップして解説" + icon: "fa fa-map" + link: /ja/scala3/guides.html + - title: "API" + description: "Scala 3 の全バージョンのAPIドキュメント" + icon: "fa fa-file-text" + link: https://dotty.epfl.ch/api/index.html + - title: "Language Reference" + description: "Scala 3 の言語仕様" + icon: "fa fa-book" + link: https://dotty.epfl.ch/docs/reference/overview.html +--- \ No newline at end of file diff --git a/_ja/scala3/new-in-scala3.md b/_ja/scala3/new-in-scala3.md new file mode 100644 index 0000000000..d8dcb3b415 --- /dev/null +++ b/_ja/scala3/new-in-scala3.md @@ -0,0 +1,126 @@ +--- +layout: singlepage-overview +title: New in Scala 3 +scala3: true +--- + +Scala 3 は Scala 2 から大幅な改善が行われ、さまざまな新機能が追加されている。 +ここでは Scala 3 の特に重要な変更点を概観する。 + +より詳しく知りたい方は以下の参考リンクを参照。 + +- [Scala 3 Book]({% link _overviews/scala3-book/introduction.md %}) は Scala を書いたことがない開発者向けに書かれている。 +- [Syntax Summary][syntax-summary] では Scala 3 で新しく追加されたシンタックスを解説している。 +- [Language Reference][reference] を見ればScala 2 と Scala 3 の変更点を詳しく確認できる。 +- Scala 2 から Scala 3 への移行を考えている方は[Migration Guide][migration] を参照。 + +## What's new in Scala 3 +Scala 3 は Scala 2 を徹底的に見直して再設計されている。核心部分で、型システムの多くの面が変更されより原理原則に基づいたものになった。この変更によって新機能(ユニオン型)が使えるようになったことにくわえて、なにより型システムがさらに使いやすくなった。 例えば、[型推論][type-inference] や overload resolution が改善された. + +### 新機能 & 特長: 文法 +(重要度の低い)多くの文法の整理に加えて、Scala 3 の文法は次のように改善された。 + +- 制御構造( `if`, `while`, や `for`)を書く際に括弧を省略してより簡潔に書けるようになった。 ([new control syntax][syntax-control]) +- `new` キーワードがオプショナルになった。 (_aka_ [creator applications][creator]) +- [Optional braces][syntax-indentation]: クロージャを中括弧`{}`ではなくインデントで表現できるようになった。 +- [ワイルドカード型][syntax-wildcard] が `_` から `?` に変更された。 +- Implicitsとその文法が [大幅に修正][implicits]された。 + +### Opinionated: Contextual Abstractions +それぞれを組み合わせることで高い(そして時には見たこともないような)表現力を発揮する一連の強力な機能をユーザーにあたえることがScalaの当初のコアコンセプトとしてあった。(これは今でもある程度は当てはまる。) 例えば _implicit_ の機能は、コンテキストの受け渡し、型レベル演算、型クラス、暗黙の変換、既存クラスの拡張メソッドなどに使われている。 + +これらのユースケースを参考にして、Scala 3 では少し違ったアプローチをとっている。Scala 3 では、`implicit`がどのようなメカニズムによるものか、ということよりもどのような意図で使われるのかに焦点を当てている。 + +Scala 3 ではひとつの強力な機能として`implicit`を提供するのではなく、開発者がその意図を表現しやすいように複数の異なる言語機能として提供している。 + +- **Abtracting over contextual information**. [Using clauses][contextual-using]を使って呼び出し時に利用可能で、暗黙に引き渡されるべき情報を抽象化することができる。Scala 2 からの改善としては、`using` 節が型だけで指定できるようになったことが挙げられる。 これによって明示的に参照されることのない関数の引数に命名する必要がなくなった。 +- **Providing Type-class instances**. [Given instances][contextual-givens] を使ってある型に対応する _canonical value_ を定義することができる。実装を公開することなく、型クラスを使ったプログラミングをよりわかりやすく書ける。 + +- **Retroactively extending classes**. Scala 2 では拡張メソッドは暗黙の変換か implicit classを使って書くことができた. 一方 Scala 3 では [extension methods][contextual-extension] が直接的に言語使用に含まれているのでよりわかりやすいエラーメッセージを表示できる。型推論も改善された。 +- **Viewing one type as another**. 暗黙の変換は型クラス`Conversion`のインスタンスとしてゼロから [再設計][contextual-conversions]された。 +- **Higher-order contextual abstractions**. 全く新しい機能である [context functions][contextual-functions] は暗黙の引数をとる関数型を第一級オブジェクトとして扱う。この機能はライブラリ作者にとって重要である。また、簡潔なドメイン特化言語(DSL)を記述するのにも役立つ。 + +- **Actionable feedback from the compiler**. コンパイラが暗黙の引数の解決に失敗した場合、解決に役立つ [import suggestions](https://www.scala-lang.org/blog/2020/05/05/scala-3-import-suggestions.html) を提示する。 + +### Say What You Mean: 型システムの改善 +型推論の大幅な改善に加えて、 Scala 3 の型システムは他にも様々な新機能がある。これらの機能は型で不変な値を静的に表現するパワフルな手段を提供する。 + +- **Enumerations**. [Enums][enums] は case class と上手く組み合わせられるよう、また代数的データ型[algebraic data types][enums-adts]の新しい標準をつくるために再設計された + +- **Opaque Types**. [opaque type aliases][types-opaque]を使うとパフォーマンス低下の懸念なしに実装の詳細を隠ぺいできる。 Opaque types は値クラスにとってかわる概念だ。Opaque types を使うと Boxing のオーバーヘッドを起こすことなく抽象化のバリアを設定できる。 + +- **Intersection and union types**. 型システムの基盤を刷新したことで、新しい型システムの機能が使えるようになった: 交差型 [intersection types][types-intersection](`A & B` と表記する)のインスタンスは `A` でありかつ `B`であるような型のインスタンスだ。 合併型[union types][types-union](`A | B` と表記する) のインスタンスは `A`または`B`のどちらか一方の型のインスタンスだ。 これらの2つの構成体は開発者が継承ヒエラルキー以外の方法で柔軟に型制約を表現できるようにする。 + +- **Dependent function types**. Scala 2 ではすでに引数の型に応じて返り値の型を変化させることができました。Scala 3 ではこのパターンをさらに抽象化することができ、[dependent function types][types-dependent]を表現することができる。 つまり `type F = (e: Entry) => e.Key` というふうに、返り値の型が引数によって変化するように書けます。 + +- **Polymorphic function types**. dependent function types のように Scala 2 では型パラメータを受け取るメソッドを定義することができました。 しかし、開発者はこれらのメソッドをさらに抽象化することはできませんでした。Scala 3 では、`[A] => List[A] => List[A]` といった書き方をする[polymorphic function types][types-polymorphic] を使って引数に加えて型引数をとるような関数を抽象化できる。 + +- **Type lambdas**. Scala 2 で[compiler plugin](https://github.com/typelevel/kind-projector)を使わないと表現できなかった型ラムダは Scala 3 では第一級の機能としてサポートされている。: 型ラムダは補助的な型を定義しないでも高階型引数として引数を受け渡せる型レベルの関数である。 +- **Match types**. 暗黙の型解決を使って型レベル演算をエンコードする代わりに、Scala 3 では型のパターンマッチング[matching on types][types-match]をサポートしている。 型レベルの演算を型チェックと統合することでエラーメッセージをわかりやすく改善し、また複雑なエンコーディングをしなくていいようにしている。 + + +### 再構想: オブジェクト指向プログラミング +Scala は常に関数型プログラミングとオブジェクト指向プログラミングの間のフロンティアにある。そして Scala 3 はその境界を両方に広げます。 +先に言及した型システムの変更と contextual abtstractions の再設計によって、関数型プログラミングを以前にも増して簡単に書けるようになった。 +同時に、次に掲げる新機能を使うと _オブジェクト指向設計_ をうまく構造化してベストプラクティスを実践しやすくなる。 +- **Pass it on**. Trait は class のように 引数をとれるようになった。詳しくは [parameters][oo-trait-parameters] をご覧ください。 これによって trait はソフトウェアをモジュールに分解するツールとしてよりいっそうパワフルになった。 +- **Plan for extension**. 継承を意図していないクラスが継承されてしまうことはオブジェクト指向設計において長年の問題でした。この問題に対処するため Scala 3 では [open classes][oo-open]の概念を導入することで _明示的に_ クラスを継承可能であるとしめすようライブラリ作者に要求するようにしました。 +- **Hide implementation details**. ふるまいを実装した Utility traits は推論される型に含まれるべきでない場合がある。Scala 3 ではそのようなtraitsに [transparent][oo-transparent] とマークすることで継承をユーザーに公開しないようにすることができる。 +- **Composition over inheritance**. このフレーズはしばしば引用されるが、実装するのは面倒だ。 しかし Scala 3 の [export clauses][oo-export]を使えば楽になる。imports と対称的に、 export clauses はオブジェクトの特定のメンバーへアクセスするためのエイリアスを定義する。 +- **No more NPEs**. Scala 3 はかつてないほど null 安全だ。: [explicit null][oo-explicit-null] によって `null` を型ヒエラルキーの外側に追い出しました。これによってエラーを静的にキャッチしやすくなる。また、 [safe initialization][oo-safe-init]の追加的なチェックで初期化されていないオブジェクトへのアクセスを検知できる。 + +### Batteries Included: メタプログラミング +Scala 2 のマクロはあくまで実験的な機能という位置づけだが、Scala 3 ではメタプログラミングに役立つ強力なツールが標準ライブラリに入っている。 + + [macro tutorial]({% link _overviews/scala3-macros/index.md %}) のページに異なった機能についての詳しい情報がある。特に Scala 3 は次のようなメタプログラミングのための機能を提供している。 + +- **Inline**. [inline][meta-inline] を使うことで値やメソッドをコンパイル時に評価できる。 このシンプルな機能はさまざまなユースケースに対応している。また同時に`inline`はより高度な機能のエントリーポイントとしても使える。 +- **Compile-time operations**. [`scala.compiletime`][meta-compiletime] パッケージには inline method を実装するのに役立つ追加的な機能が含まれている。 +- **Quoted code blocks**. Scala 3 には [quasi-quotation][meta-quotes]という新機能がある。この機能を使えば扱いやすい高レベルなインターフェースを介してコードを組み立てたり分析したりすることができる。 `'{ 1 + 1 }` と書くだけで1 と 1 を足すASTを組み立てられる。 +- **Reflection API**. もっと高度なユースケースでは [TASTy reflect][meta-reflection]を使ってより細かくプログラムツリーを操作したり生成したりすることができる。 + + +Scala 3 のメタプログラミングについてもっと知りたいかたは、 こちらの[tutorial][meta-tutorial]を参照。 + + +[enums]: {{ site.scala3ref }}/enums/enums.html +[enums-adts]: {{ site.scala3ref }}/enums/adts.html + +[types-intersection]: {{ site.scala3ref }}/new-types/intersection-types.html +[types-union]: {{ site.scala3ref }}/new-types/union-types.html +[types-dependent]: {{ site.scala3ref }}/new-types/dependent-function-types.html +[types-lambdas]: {{ site.scala3ref }}/new-types/type-lambdas.html +[types-polymorphic]: {{ site.scala3ref }}/new-types/polymorphic-function-types.html +[types-match]: {{ site.scala3ref }}/new-types/match-types.html +[types-opaque]: {{ site.scala3ref }}/other-new-features/opaques.html + +[type-inference]: {{ site.scala3ref }}/changed-features/type-inference.html +[overload-resolution]: {{ site.scala3ref }}/changed-features/overload-resolution.html +[reference]: {{ site.scala3ref }}/overview.html +[creator]: {{ site.scala3ref }}/other-new-features/creator-applications.html +[migration]: https://scalacenter.github.io/scala-3-migration-guide + +[implicits]: {{ site.scala3ref }}/contextual/motivation.html +[contextual-using]: {{ site.scala3ref }}/contextual/using-clauses.html +[contextual-givens]: {{ site.scala3ref }}/contextual/givens.html +[contextual-extension]: {{ site.scala3ref }}/contextual/extension-methods.html +[contextual-conversions]: {{ site.scala3ref }}/contextual/conversions.html +[contextual-functions]: {{ site.scala3ref }}/contextual/context-functions.html + +[syntax-summary]: {{ site.scala3ref }}/syntax.html +[syntax-control]: {{ site.scala3ref }}/other-new-features/control-syntax.html +[syntax-indentation]: {{ site.scala3ref }}/other-new-features/indentation.html +[syntax-wildcard]: {{ site.scala3ref }}/changed-features/wildcards.html + +[meta-tutorial]: {% link _overviews/scala3-macros/index.md %} +[meta-inline]: {% link _overviews/scala3-macros/tutorial/inline.md %} +[meta-compiletime]: {% link _overviews/scala3-macros/tutorial/compiletime.md %} +[meta-quotes]: {% link _overviews/scala3-macros/tutorial/quotes.md %} +[meta-reflection]: {% link _overviews/scala3-macros/tutorial/reflection.md %} + +[oo-explicit-null]: {{ site.scala3ref }}/other-new-features/explicit-nulls.html +[oo-safe-init]: {{ site.scala3ref }}/other-new-features/safe-initialization.html +[oo-trait-parameters]: {{ site.scala3ref }}/other-new-features/trait-parameters.html +[oo-open]: {{ site.scala3ref }}/other-new-features/open-classes.html +[oo-transparent]: {{ site.scala3ref }}/other-new-features/transparent-traits.html +[oo-export]: {{ site.scala3ref }}/other-new-features/export.html diff --git a/_ja/tour/traits.md b/_ja/tour/traits.md index 887eed1741..81b7dc7046 100644 --- a/_ja/tour/traits.md +++ b/_ja/tour/traits.md @@ -84,5 +84,5 @@ animals.append(dog) animals.append(cat) animals.foreach(pet => println(pet.name)) // Prints Harry Sally ``` -`trait Pet` が持つ抽象フィールド `name`は、Cat と Dog のコンストラクタで実装されました。 +`trait Pet` が持つ抽象フィールド `name`は、Cat と Dog のコンストラクタで実装された。 最終行では、`Pet` トレイトの全てのサブタイプの中で実装される必要がある `pet.name` を呼んでいます。 diff --git a/_ja/tutorials/scala-for-java-programmers.md b/_ja/tutorials/scala-for-java-programmers.md index 361d550f47..a7798b69b2 100644 --- a/_ja/tutorials/scala-for-java-programmers.md +++ b/_ja/tutorials/scala-for-java-programmers.md @@ -425,7 +425,7 @@ Scala は普通のクラスと同様にケースクラスにメソッド定義 おそらく Java プログラマーにとってトレイトを理解するもっとも簡単な方法は、コードを含むことができるインターフェースとしてとらえることでしょう Scala では、クラスがトレイトから継承するとき、トレイトのインターフェースを実装し、トレイトに含まれるコードをすべて継承します。 -(注:Java 8 からは、Java インターフェースも同様にコードを含めるようになりました。`default` キーワードをつけるか、または static メソッドとして) +(注:Java 8 からは、Java インターフェースも同様にコードを含めるようになった。`default` キーワードをつけるか、または static メソッドとして) トレイトの有用性を見るため、古典的な例、順序付きオブジェクトを見てみましょう。 あるクラスのオブジェクト同士を順序比較できると、例えば並び替え(ソート)できて、便利なことが多いです。 diff --git a/scala3/getting-started.md b/scala3/getting-started.md index 0f5e334fd1..f3fcfb1a8a 100644 --- a/scala3/getting-started.md +++ b/scala3/getting-started.md @@ -1,6 +1,7 @@ --- layout: singlepage-overview title: Getting Started with Scala 3 +languages: ["ja"] --- diff --git a/scala3/new-in-scala3.md b/scala3/new-in-scala3.md index 6516287849..8f28f0d5af 100644 --- a/scala3/new-in-scala3.md +++ b/scala3/new-in-scala3.md @@ -1,6 +1,7 @@ --- layout: singlepage-overview title: New in Scala 3 +languages: ["ja"] --- The upcoming, exciting new version of Scala 3 brings many improvements and new features. Here we provide you with a quick overview of the most important