LoginSignup
0
0

More than 1 year has passed since last update.

haskellでUTF8でwriteFile

Posted at

HaskellでUTF8でファイルを書く方法です。シンプルな方法が調べても見つからなかったのでメモを残しておきます。

次のExtraというパッケージを使います。
https://hackage.haskell.org/package/extra-1.7.10/docs/Extra.html

package.yamlの依存packageにextraを明記。

package.yaml
dependencies:
- extra

stack ghciで対話環境を起動して日本語のファイルを書き出してみます。

ghci> import System.IO.Extra
ghci> writeFileUTF8 "test.txt" "あいうえお"

これでできたtext.txtの文字コードを見てみましょう(nkfコマンドを使用)。

$ nkf -g text.txt
UTF-8

簡単ですね!

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0