計算機科学のブログ

Haskellを使用するための準備 対話型インターフェイス、GHCi、単純な数値計算、累乗

入門Haskellプログラミング (Will Kurt(著)、株式会社クイープ(監修、翻訳)、翔泳社)のLESSON 1(Haskellを使用するための準備)、1.6(練習問題)Q1-1の解答を求めてみる。

入出力結果(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
λ> :t (**)
(**) :: Floating a => a -> a -> a
*Main Lib Paths_testprogram
λ> 2 ** 123
1.0633823966279327e37
it :: Floating a => a
(0.02 secs, 530,544 bytes)
*Main Lib Paths_testprogram
λ> :t (^)
(^) :: (Integral b, Num a) => a -> b -> a
*Main Lib Paths_testprogram
λ> 2 ^ 123
10633823966279326983230456482242756608
it :: Num a => a
(0.02 secs, 528,416 bytes)
*Main Lib Paths_testprogram
λ> :quit
Leaving GHCi.
%