Posted by: hahnah Posted on:
How I became interested in Roc
I recently saw this tweet and decided to take a look. It seems that Roc's website has been created.
I've known that Richard Feldman has been working full-time on the Roc language for some time.
https://twitter.com/rtfeldman/status/1617575567162851347
https://twitter.com/rtfeldman/status/1617575567162851347
He was involved in the programming language Elm , and in addition to developing products and libraries using Elm, he also worked to popularize Elm by giving talks at conferences and writing books.
In fact, he was also the former boss of Elm developer Evan Czaplicki, so he may have been involved in the development of Elm itself.
Elm is my favorite language because of its simplicity, robustness, high performance, and developer friendliness.
Roc's concept seems to be Elm-inspired by him, so Roc might also be his favorite language.
So, I was curious to see what kind of language Roc was, so I decided to take a look.
Scenes using Roc
As an example, it can be used in the following scenes.
- Script used in CLI
- Web server
- Integration into other languages
- It seems possible to call Roc functions from Python, Node.js, Swift, WebAssembly, JVM languages, etc. It is possible to use other languages as long as they can call C language programs.
What does code written in Roc look like?
You can get a rough idea of what code written in Roc looks like by looking at the Examples .
Since I'm looking for a programming language for web servers, I also looked at an example of a web server that processes HTTP requests .
This repository has more sample code for implementing a web server in Roc.
By watching the tutorial , you can get a general understanding of grammar and language functions.
If you want to write it yourself right away, the quickest way is to use REPL on the web.
It has syntax and functions similar to those found in ML languages.
I really like the way these languages are written.
When
I first encountered ML languages a long time ago, I was confused, but
as I started using them and started to understand them more and more,
my impression completely changed.
Roc is actually a very simple language, with little grammar, and is probably an easy language.
However, I think that any kind of language is difficult when you come into contact with a language that you are completely unfamiliar with. It's true that you have to work a little harder at first.
Well, let me tell you, even if the Roc looks foreign to you, don't let that put you off. That's it.
Current status of Roc
Roc is still in development.
As of November 2023, it is a nightly-build version that has not been versioned yet.
Maybe you're losing interest in Roc because it's not practical at the moment?
To be honest, that's why I'm moderately interested in it.
Well, we'll have to wait a few years to see how far that point will go.
Characteristics of Roc (what we are aiming for)
Again, Roc is still a work in progress.
Therefore, please note that not all features are fully
equipped at this time, and some theoretical references are included in
the design.
Let's take a look at the features of Roc.
Feature 1. Fast
Roc is fast in two ways.
First, it runs quickly
Roc code is compiled into machine language or WebAssembly.
Machine language means that it runs directly on the host machine rather than on a VM.
In that case, the execution speed will generally be faster
than JVM-based languages (Java, Scala, Kotlin, etc.) and .NET-based
languages (C#, F#, Visual Basic, etc.).
Even when compiled to WebAssembly, high-speed execution on Node.js is expected. (It is expected to be faster than JavaScript/TypeScript in the Node.js environment.)
By the way, WebAssembly seems to work on a browser, but I didn't really understand that point.
C, C++, Zig, and unsafe Rust are at the top of the list of fast-running languages, but in theory, Roc cannot reach them.
Roc is a memory-safe language, and memory management is automatic (like garbage collection).
It can't compete with C and C++, which are not memory safe,
and it can't compete with Rust (which I mentioned earlier as unsafe
Rust), which uses memory safety to improve performance.
Rust
(safe Rust) has manual memory management, which means it has less
runtime overhead and theoretically better performance than languages
with automatic memory management.
Roc has automatic memory management, so it's no match for safe Rust.
一言で、Roc の実行時パフォーマンスの目標がどのくらいかというと、ガベージコレクションで自動メモリ管理する高速でメインストリームにある言語を上回ることだ。
Go, C#, Java, JavaScript あたりを超えること。
余談。
ところで、Rocの最適化にはLLVMなどを使っているらしいが、よく知らなかったので調べてみると面白い技術だった。
間違ったことを紹介してしまいそうなのでここには書かないが。
また、ビルド速度が早い
開発時のビルドが即時だと感じられるようにすることで、高速な開発の実現を目指している。
現状だとWebAssembly, Linux x64, Windows x64 では特にビルドが早いとのこと。
また、現時点では development backend (dev環境、devサーバーなどと表現した方が伝わる?)が用意されているのはWebAssemblyのみで、macOSとLinuxではREPLの提供に留まっている。
Windows対応はまだのようだ。
dev用ではなくproduction用のビルドであれば、現時点でもいずれの環境にも対応している。
development backend 用のビルドにはLLVMが使えず、直接マシンコードを生成する必要がある、というのが対応ができていない背景にあるらしい。
また、macOS向けのdevelopment backend のビルドは Surgical Linking と呼ばれる仕組みが備わっていない関係で、他よりも目立って遅くなってしまうらしい。
macOS意外にも、Intel x64 アーキテクチャのものも同じ理由で遅い。
特徴2. 開発者フレンドリー
フレンドリーなコミュニティを持つことと、開発者フレンドリーな言語であることを重視しているとのこと。
まず、すっきりと明確な構文を持っていて、フォーマッタが標準で提供されています。
コーディングスタイルの議論や整形に時間を費やす必要はない。
次に、健全な型システムと支援の行き届いたコンパイラ。
コンパイルエラーのメッセージは、具体的なエラーの原因箇所と、修正方法の提案、ヒントを与えてくれる。
健全な型システムに守られているので、実行時エラーに怯えることはかなり抑えられるのはありがたい。
コードのリファクタリングも思いっきりできる。コードも健全に保ちやすいということだ。
健全な型システムは個人的にはほぼ必須条件。
他には、テスト用のコマンドや構文も標準で用意されているなどの点がある。
特徴3. 関数型
Rocは関数型パラダイムの言語だ。
最近は関数型あるいはオブジェクト指向を主軸にしつつもマルチパラダイムな言語が多いが、Rocはただ関数型パラダイムのみ。
次のような特徴がある。
- イミュータブル
- 純粋関数
- 副作用よりも作用?(effect) を管理する
- effect をあまり理解していないのだが、同期処理(副作用)ではなく非同期処理(作用)を管理する、というような表現がされていた。
良さそうなのだが、少し気になった点がある。
REPLで確認したところ、関数の部分適用はできないみたいだ。関数のカリー化もされない。
書き方次第ではできるんだろうか?
コメントを残す