計算機科学のブログ

Haskellを使用するための準備 Haskellとのやり取り:GHCi

入門Haskellプログラミング (Will Kurt(著)、株式会社クイープ(監修、翻訳)、翔泳社)のLESSON 1(Haskellを使用するための準備)、1.3(Haskellとのやり取り:GHCi)、クイックチェック 1-2の解答を求めてみる。

コード

testprogram/app/Main.hs

module Main where

import Lib

main :: IO ()
main = do
  print "Hello Haskell!"

入出力結果(Terminal, Zsh)

% stack ghci
Using main module: 1. Package `testprogram' component testprogram:exe:testprogram-exe with main-is file: /Users/…/testprogram/app/Main.hs
The following GHC options are incompatible with GHCi and have not been passed to it: -threaded
Configuring GHCi with the following packages: testprogram

* * * * * * * *

Warning: Multiple files use the same module name:
         * Paths_testprogram found at the following paths
           * /Users/…/testprogram/.stack-work/dist/x86_64-osx/Cabal-3.4.1.0/build/autogen/Paths_testprogram.hs (testprogram:lib)
           * /Users/…/testprogram/.stack-work/dist/x86_64-osx/Cabal-3.4.1.0/build/testprogram-exe/autogen/Paths_testprogram.hs (testprogram:exe:testprogram-exe)
* * * * * * * *

GHCi, version 9.0.2: https://www.haskell.org/ghc/  :? for help
macro 'doc' overwrites builtin command.  Use ':def!' to overwrite.
(0.00 secs, 0 bytes)
(0.00 secs, 0 bytes)
Loaded GHCi configuration from /Users/…/.ghc/ghci.conf
[1 of 3] Compiling Lib              ( /Users/…/testprogram/src/Lib.hs, interpreted )
[2 of 3] Compiling Main             ( /Users/…/testprogram/app/Main.hs, interpreted )
[3 of 3] Compiling Paths_testprogram ( /Users/…/testprogram/.stack-work/dist/x86_64-osx/Cabal-3.4.1.0/build/autogen/Paths_testprogram.hs, interpreted )
Ok, three modules loaded.
Loaded GHCi configuration from /private/var/folders/wj/52wjq8dn0fj1qltsnx3xxpnh0000gn/T/haskell-stack-ghci/4fd5f6ce/ghci-script
*Main Lib Paths_testprogram
λ> :load Main
[1 of 2] Compiling Lib              ( /Users/…/testprogram/src/Lib.hs, interpreted )
[2 of 2] Compiling Main             ( /Users/…/testprogram/app/Main.hs, interpreted )
Ok, two modules loaded.
(0.01 secs,)
*Main
λ> main
"Hello Haskell!"
it :: ()
(0.00 secs, 513,480 bytes)
*Main
λ> :quit
Leaving GHCi.
%