Haskell - コードの整理とプロジェクトのビルド - QuickCHeckを使ったプロパティテスト - 新しいプロジェクトを開始する
入門Haskellプログラミング (Will Kurt(著)、株式会社クイープ(監修、翻訳)、翔泳社)の UNIT6(コードの整理とプロジェクトのビルド)、LESSON 36(QuickCHeckを使ったプロパティテスト)、36.1(新しいプロジェクトを開始する)、 クイックチェック 36-1の解答を求めてみる。
コード
palindrome-testing/app/Main.hs
module Main (main) where
import Lib
main :: IO ()
main = do
mapM_ (\text -> putStrLn $ mconcat ["'", text, "':", show (isnPalindrome text)])
["", "a", "ab", "racecar"]
コード
palindrome-testing/src/Lib.hs
module Lib where
isnPalindrome :: String -> Bool
isnPalindrome text = text == reverse text
入出力結果(Terminal, Zsh)
% stack run
palindrome-testing-0.1.0.0: unregistering (local file changes: app/Main.hs)
palindrome-testing> build (lib + exe) with ghc-9.8.4
Preprocessing library for palindrome-testing-0.1.0.0..
Building library for palindrome-testing-0.1.0.0..
Preprocessing executable 'palindrome-testing-exe' for palindrome-testing-0.1.0.0..
Building executable 'palindrome-testing-exe' for palindrome-testing-0.1.0.0..
[1 of 2] Compiling Main [Source file changed]
[3 of 3] Linking .stack-work/dist/aarch64-osx/ghc-9.8.4/build/palindrome-testing-exe/palindrome-testing-exe [Objects changed]
ld: warning: -U option is redundant when using -undefined dynamic_lookup
palindrome-testing> copy/register
Installing library in /Users/.../palindrome-testing/.stack-work/install/aarch64-osx/e7436b3217cf53d6b9beeebd2bdc5dd8dcab6f8595b8bde259631442ce745f25/9.8.4/lib/aarch64-osx-ghc-9.8.4/palindrome-testing-0.1.0.0-79lc3QtIB5sEppb6jDwN1g
Installing executable palindrome-testing-exe in /Users/.../palindrome-testing/.stack-work/install/aarch64-osx/e7436b3217cf53d6b9beeebd2bdc5dd8dcab6f8595b8bde259631442ce745f25/9.8.4/bin
Registering library for palindrome-testing-0.1.0.0..
'':True
'a':True
'ab':False
'racecar':True
%