[Elm] Windowsマシンにインストール

フロントエンドの知識や技術が皆無なので、なにか触ってみようと思いつつ数年たった。

Elmという響きがいいので、触ってみようと思う。響きがいいような気がするのは北の方に住んでるからなのかな。

Elmガイドに沿って進めていこうと思う。で、今回はインストール。

ガイド内のリンクからインストーラをダウンロード。ヴァージョンは0.19でした。

elm repl

>elm repl
---- Elm 0.19.0 ----------------------------------------------------------------
Read <https://elm-lang.org/0.19.0/repl> to learn more: exit, help, imports, etc.
--------------------------------------------------------------------------------
> 1 / 2
0.5 : Float
> "sss"
"sss" : String
> [1,2,3,4]
[1,2,3,4] : List number
> ["a","b","c","d"]
["a","b","c","d"] : List String

型が異なるものをリストに入れるとエラーになる。エラーメッセージも親切。

> [1,"a"]
-- TYPE MISMATCH ----------------------------------------------------------- elm
The 2nd element of this list does not match all the previous elements:
4|   [1,"a"]
       ^^^
The 2nd element is a string of type:
   String
But all the previous elements in the list are:
   number
Hint: Everything in the list needs to be the same type of value. This way you
never run into unexpected values partway through. To mix different types in a
single list, create a "union type" as described in:
<http://guide.elm-lang.org/types/union_types.html>
Hint: Try using String.toInt to convert it to an integer?


elm reactor

ガイドに記載のリンクから、チュートリアルリポジトリをcloneして、elm reactorで起動しアクセス。
http://localhost:8000

最初にアクセスした際にわりとレスポンスまでに時間がかかった。コンパイルしている時間なんだろうか?全然仕組みが理解できていない。。。

exampleがいくつか含まれているので、中身を見ていけば仕組みも少しずつわかりそう。

以上。


関数の部分を少しだけ。

> isNegative n = n < 0
<function> : number -> Bool
> isNegative 4
False : Bool
> isNegative -10
True : Bool
> add a b = a + b
<function> : number -> number -> number
> add 2 5
7 : number
> add 8 -9
-1 : number
> add 4
<function> : number -> number
> add4 = add 4
<function> : number -> number
> add4 10
14 : number

なんだか気分がいい。


この記事が気に入ったらサポートをしてみませんか?