elm環境作成(hGetContents: invalid argument (invalid byte sequence)解決)
elmをWindows10にインストールして、サンプルをコンパイルしてみた。
インストールはhttp://elm-lang.org/installからダウンロードし、
Elm-Platform-0.16.exeを実行するだけ。
ファイル名からわかる通り、バージョンは0.16。
サンプルをファイルに保存した。(新たにフォルダを作成し、そこにutf8で保存)
import Graphics.Element exposing (..) main = show "Hello!"
次に、コマンドプロンプトを立ち上げ、コンパイルすると
以下のように失敗する。
D:\elm_work\hello>elm-make Hello.elm --output hello.html Some new packages are needed. Here is the upgrade plan. Install: elm-lang/core 3.0.0 Do you approve of this plan? (y/n) y Downloading elm-lang/core Packages configured successfully! [========================== ] - 17 / 32elm-make: elm-stuff\packages\elm-lang\core\3.0.0\src\Graphics\Element.elm: hGetContents: invalid argument (invalid byte sequence) elm-make: thread blocked indefinitely in an MVar operation D:\elm_work\hello>
そこで、コマンドプロンプトの文字コードを「chcp 65001」と入力し、UTF-8に変更する。
(参考:文字コードの設定(CHCP) - ウィンドウの操作 - コマンドプロンプトの使い方)
Active code page: 65001 D:\elm_work\hello>elm-make Hello.elm --output hello.html -- SYNTAX PROBLEM ---------------------------------------------------- Hello.elm I ran into something unexpected when parsing your code! 1│ import Html exposing (text) ^ I am looking for one of the following things: "{-|" a module declaration a port declaration a type declaration a value definition an import an infix declaration whitespace Detected errors in 1 module.
文法が違うらしい(ここはまだまだ勉強不足)ので他のサンプルを探し、
https://github.com/evancz/elm-examplesから、「Hello.elm」を入手し、コンパイルすると成功した。
ファイルの文字コードはsjisでもいいみたい?
D:\elm_work\hello>elm-make hello.elm --output hello.html Success! Compiled 16 modules. Successfully generated hello.html
ここまで来て、元々の簡単なサンプル
import Graphics.Element exposing (..) main = show "Hello!"
でも大丈夫かと思ったら、コンパイルできた。(よく読んでなかったが、文法の問題ではなかったらしい)
取り敢えず、なんとなく環境ができた気がする。