특정 언어나 플랫폼의 개발환경을 아무런 배경없이 설치하려면 알아야할게 많고, 시간도 많이 걸린다. 이를 위해 패키지와 프로젝트를 관리하는 프로그램들을 같이 제공한다. 구글에서 사용하는 flutter 가 이러한 방법을 사용하고 있다.
GHCup 은 Haskell 패키지 관리자이다. GHC, HLS, Stack, cabal 패키지의 버전을 관리한다.
PowerShell 에서 다음 명령을 사용하여 설치한다. 설치 경로를 지정하고, 추가 패키지는 설치하는 것이 좋다.
Set-ExecutionPolicy Bypass -Scope Process -Force;[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; try { & ([ScriptBlock]::Create((Invoke-WebRequest https://www.haskell.org/ghcup/sh/bootstrap-haskell.ps1 -UseBasicParsing))) -Interactive -DisableCurl } catch { Write-Error $_ }
tui 명령을 사용하여 현재 상태를 확인할 수 있다.
ghcup tui
프로젝트의 관리는 Stack 을 사용한다. 여기서는 기본적인 명령들을 살펴본다. 보다 다양하고 자세한 사항은 stack 튜토리얼 을 참고한다.
기본 템플릿을 사용하여 Haskell 프로젝트를 생성한다.
stack new [PROJECT] [TEMPLATE]
프로젝트를 빌드한다.
stack build
프로젝트를 실행한다. FILENAME 인자를 사용하여 특정 명령을 지정할 수 있다.
stack run [FILENAME]
이제 간단한 프로젝트를 만들어보자.
stack new helloworld new-template
그럼 helloworld 디렉토리 하위 프로젝트 관련 파일들이 생성된 것을 볼 수 있다.
이제 프로젝트를 빌드하여 실행파일로 만들어보자.
stack build
만들어진 실행파일을 실행해 보자.
$ stack run helloworld helloworld-0.1.0.0: unregistering (local file changes: .stack-work\dist\f1a1ac53\build\autogen\Paths_helloworld.hs .stack-work\dist\f1a1ac53\build\hello...) helloworld> build (lib + exe) with ghc-9.4.8 Preprocessing library for helloworld-0.1.0.0.. Building library for helloworld-0.1.0.0.. Preprocessing executable 'helloworld-exe' for helloworld-0.1.0.0.. Building executable 'helloworld-exe' for helloworld-0.1.0.0.. helloworld> copy/register Installing library in C:\Users\kjkan\dev\Projects\helloworld\.stack-work\install\df8bf79e\lib\x86_64-windows-ghc-9.4.8\helloworld-0.1.0.0-IfCG3xlR0IUdqFrBiuXpS Installing executable helloworld-exe in C:\Users\kjkan\dev\Projects\helloworld\.stack-work\install\df8bf79e\bin Registering library for helloworld-0.1.0.0.. someFunc
개발환경은 haskell-mode 를 사용한다. 언어서버와의 연동, 오류분석, 코드분석등을 위해 haskell-mode 실행시 추가 패키지를 로드한다.
(use-package haskell-mode :ensure t :bind (:map interactive-haskell-mode-map ("M-/" . helm-lsp-code-actions) ("M-?" . xref-find-references) ("M-." . xref-find-definitions)) :hook (haskell-mode . company-mode) (haskell-mode . display-line-numbers-mode) (haskell-mode . flycheck-mode) (haskell-mode . lsp-mode) (haskell-mode . lsp-completion-mode) (haskell-mode . show-paren-mode) (haskell-mode . whitespace-cleanup-mode))