計算機科学のブログ

コードの整理とプロジェクトのビルド stackを使ってプロジェクトをビルドする プロジェクトの構造を理解する appフォルダ、srcフォルダ、testフォルダ

入門Haskellプログラミング (Will Kurt(著)、株式会社クイープ(監修、翻訳)、翔泳社)のUNIT6(コードの整理とプロジェクトのビルド)、LESSON 35(stackを使ってプロジェクトをビルドする)、35.2(プロジェクトの構造を理解する)、appフォルダ、srcフォルダ、testフォルダ、クイックチェック 35-2の解答を求めてみる。

文字列「someFunc」を出力する。

実際に確認。

コード

lesson/app/Main.hs

module Main (main) where

import Lib

main :: IO ()
main = someFunc

lesson/src/Lib.hs

module Lib
    ( someFunc
    ) where

someFunc :: IO ()
someFunc = putStrLn "someFunc"

入出力結果(Terminal, Zsh)

% stack build
Building all executables for `palindrome-checker' once. After a successful build of all of them, only specified executables will be rebuilt.
palindrome-checker> configure (lib + exe)
Configuring palindrome-checker-0.1.0.0...
palindrome-checker> build (lib + exe)
Preprocessing library for palindrome-checker-0.1.0.0..
Building library for palindrome-checker-0.1.0.0..
[1 of 2] Compiling Lib
[2 of 2] Compiling Paths_palindrome_checker
ld: warning: -undefined dynamic_lookup may not work with chained fixups
Preprocessing executable 'palindrome-checker-exe' for palindrome-checker-0.1.0.0..
Building executable 'palindrome-checker-exe' for palindrome-checker-0.1.0.0..
[1 of 2] Compiling Main
[2 of 2] Compiling Paths_palindrome_checker
Linking .stack-work/dist/x86_64-osx/Cabal-3.4.1.0/build/palindrome-checker-exe/palindrome-checker-exe ...
palindrome-checker> copy/register
Installing library in /Users/…/palindrome-checker/.stack-work/install/x86_64-osx/2eba38e017b6fee520eef2e177472e545ca8d29a6a91bc78d77938548294ecf4/9.0.2/lib/x86_64-osx-ghc-9.0.2/palindrome-checker-0.1.0.0-Goo3MqaU7mKLSSKOblpS47
Installing executable palindrome-checker-exe in /Users/…/palindrome-checker/.stack-work/install/x86_64-osx/2eba38e017b6fee520eef2e177472e545ca8d29a6a91bc78d77938548294ecf4/9.0.2/bin
Registering library for palindrome-checker-0.1.0.0..
% stack exec palindrome-checker-exe
someFunc
%