Stack
インストール参考サイト:本気で Haskell したい人向けの Stack チュートリアル
インストール
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
$ curl –sSL https://get.haskellstack.org/ | sh $ $ tail –3 ~/.profile if [ –d “$HOME/.local/bin” ] ; then PATH=“$HOME/.local/bin:$PATH” fi $ $ stack —version Version 1.5.1 i386 hpack–0.17.1 $ which stack /usr/local/bin/stack $ eval “$(stack –bash-completion-script stack)” $ stack setup $ stack ghc — —version The Glorious Glasgow Haskell Compilation System, version 8.0.2 $ stack ghci Configuring GHCi with the following packages: GHCi, version 8.0.2: http://www.haskell.org/ghc/ :? for help Loaded GHCi configuration from /tmp/ghci26042/ghci–script Prelude> :q Leaving GHCi. $ stack install cabal–install : Copying from /home/XXXXXXXXX/.stack/snapshots/i386–linux/lts–9.12/8.0.2/bin/cabal to /home/XXXXXXXX/.local/bin/cabal Copied executables to /home/XXXXXXXX/.local/bin: – cabal $ cabal —version cabal–install version 1.24.0.2 compiled using version 1.24.2.0 of the Cabal library $ |
コーディング環境
hoogle
1 2 3 4 |
$ stack install hoogle $ which hoogle /home/t–randt/.local/bin/hoogle $ stack hoogle —init |
ghc-mod/hlint
型注釈や静的解析のため
1 2 3 4 5 6 7 |
$ stack install ghc–mod hlint $ $ which ghc–mod /home/t–randt/.local/bin/ghc–mod $ which ghc–modi /home/t–randt/.local/bin/ghc–modi $ which hlint /home/t–randt/.local/bin/hlint |
haskell-mode
emacs用mode
1 2 3 |
$ apt–get install haskell–mode $ cat ~/.emacs.d/haskell_mode.el $ |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
;; haskell–mode (autoload ‘haskell-mode “haskell-mode”) (autoload ‘haskell–cabal “haskell-cabal”) (add–to–list ‘auto-mode-alist ‘(“\\.hs$” . haskell–mode)) (add–to–list ‘auto-mode-alist ‘(“\\.lhs$” . literate–haskell–mode)) (add–to–list ‘auto-mode-alist ‘(“\\.cabal\\'” . haskell–cabal–mode)) (add–to–list ‘interpreter-mode-alist ‘(“runghc” . haskell–mode)) (add–to–list ‘interpreter-mode-alist ‘(“runhaskell” . haskell–mode)) ;; indent の有効. (add–hook ‘haskell-mode-hook ‘turn–on–haskell–indentation) (add–hook ‘haskell-mode-hook ‘turn–on–haskell–doc–mode) (add–hook ‘haskell-mode-hook ‘font–lock–mode) (add–hook ‘haskell-mode-hook ‘imenu–add–menubar–index) ;; ghci起動 ;; (setq haskell–process–type ‘stack-ghci) ;; (setq haskell-process-path-ghci “stack”) ;; (setq haskell-process-args-ghci “ghci”) (setq haskell-program-name “stack ghci”) ;; C-c C-lで起動 (add-hook ‘haskell–mode–hook ‘inf-haskell-mode) ;; ghci の起動とファイルの読み込みを一緒に行う設定. (defadvice inferior-haskell-load-file (after change-focus-after-load) “Change focus to GHCi window after C-c C-l command” (other-window 1)) (ad-activate ‘inferior–haskell–load–file) |
- Emacsの設定
- Haskell を快適に利用するための Emacs 環境の構築
- Stackをhaskell-modeで使ってみよう
- 気がついたら Emacs の Haskell を勉強する環境が整っていた話
新規プロジェクト
1 2 3 4 5 6 7 8 |
$ stack new hello $ cat hello/src/Lib.hs module Lib ( someFunc ) where someFunc :: IO () someFunc = putStrLn “Hello World!!” |
プロジェクトビルド
1 2 3 4 |
$ stack build hello $ stack exec hello Hello, World! $ |
git登録
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
$ cd hello $ stack clean —full $ git add hello $ git status ブランチ master Your branch is up–to–date with ‘origin/master’. コミット予定の変更点: (use “git reset HEAD <file>…” to unstage) new file: hello/LICENSE new file: hello/README.md new file: hello/Setup.hs new file: hello/app/Main.hs new file: hello/hello.cabal new file: hello/src/Lib.hs new file: hello/src/Lib.hs~ new file: hello/stack.yaml new file: hello/test/Spec.hs $ git commit [master 0d6c5fb] initial 9 files changed, 160 insertions(+) create mode 100644 hello/LICENSE create mode 100644 hello/README.md create mode 100644 hello/Setup.hs create mode 100644 hello/app/Main.hs create mode 100644 hello/hello.cabal create mode 100644 hello/src/Lib.hs create mode 100644 hello/src/Lib.hs~ create mode 100644 hello/stack.yaml create mode 100644 hello/test/Spec.hs $ git push Username for ‘https://bitbucket.org’: XXXXXXXX Password for ‘https://bbbae@bitbucket.org’: Counting objects: 9, done. Delta compression using up to 2 threads. Compressing objects: 100% (8/8), done. Writing objects: 100% (9/9), 2.17 KiB | 0 bytes/s, done. Total 9 (delta 2), reused 0 (delta 0) To https://bitbucket.org/XXXXXXXXXX/sample_haskell 5f363bd..0d6c5fb master -> master $ </file> |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
$ cat .emacs.d/package.el (require ‘package) ;; MELPAを追加 (add-to-list ‘package–archives ‘(“melpa” . “https://melpa.org/packages/”) t) ;; MELPA-stableを追加 (add-to-list ‘package–archives ‘(“melpa-stable” . “https://stable.melpa.org/packages/”) t) ;; Marmaladeを追加 (add-to-list ‘package–archives ‘(“marmalade” . “http://marmalade-repo.org/packages/”) t) ;; Orgを追加 (add-to-list ‘package–archives ‘(“org” . “http://orgmode.org/elpa/”) t) ;; 初期化 (package–initialize) $ |
flycheck
1 2 3 4 5 6 7 |
$ cat ~/.emacs.d/flycheck.el ;;for flycheck (add–hook ‘after-init-hook #’global–flycheck–mode) ;; for flycheck–top–tip (eval–after–load ‘flycheck ‘(custom–set–variables ‘(flycheck-display-errors-function #’flycheck–pos–tip–error–messages))) |
doctest/quickchec/hspec
1 2 3 4 5 6 7 |
$ stack install doctest $ stack exec doctest — —version doctest version 0.11.4 using version 8.0.2 of the GHC API using /home/t–randt/.stack/programs/i386–linux/ghc–8.0.2/bin/ghc–8.0.2 $ stack install hspec $ |
バックアプファイルを作らない
1 2 3 4 5 6 7 8 |
$ cat ./.emacs.d/tempfile.el ;;; backup file dir. (add–to–list ‘backup-directory-alist (cons (expand-file-name “~/”) (expand-file-name “~/temp/”))) ;;; auto save dir (add-to-list ‘auto–save–file–name–transforms `(“~/\\([^/]*/\\)*\\([^/]*\\)$” “~/temp/\\2” t)) $ |