Haskell - コードの整理とプロジェクトのビルド - QuickCHeckを使ったプロパティテスト - さまざまな種類のテスト - ghci
入門Haskellプログラミング (Will Kurt(著)、株式会社クイープ(監修、翻訳)、翔泳社)の UNIT6(コードの整理とプロジェクトのビルド)、LESSON 36(QuickCHeckを使ったプロパティテスト)、36.2(さまざまな種類のテスト)、 クイックチェック 36-1の解答を求めてみる。
コード
palindrome-testing/src/Lib.hs
module Lib where
isPalindrome :: String -> Bool
isPalindrome text = cleanText == reverse cleanText
where cleanText = filter (not . (== '!')) text
入出力結果(Terminal, Zsh)
% stack ghci
Using main module:
1. Package palindrome-testing, component
palindrome-testing:exe:palindrome-testing-exe, with main-is file:
/Users/.../palindrome-testing/app/Main.hs.
palindrome-testing> initial-build-steps (lib + exe)
Warning: The following GHC options are incompatible with GHCi and have not been
passed to it: -threaded.
Configuring GHCi with the following packages: palindrome-testing.
Warning: Multiple files use the same module name:
* Paths_palindrome_testing found at the following paths
* /Users/.../palindrome-testing/.stack-work/dist/aarch64-osx/ghc-9.8.4/build/autogen/Paths_palindrome_testing.hs
(palindrome-testing:lib)
* /Users/.../palindrome-testing/.stack-work/dist/aarch64-osx/ghc-9.8.4/build/palindrome-testing-exe/autogen/Paths_palindrome_testing.hs
(palindrome-testing:exe:palindrome-testing-exe)
GHCi, version 9.8.4: https://www.haskell.org/ghc/ :? for help
[1 of 4] Compiling Lib ( /Users/.../palindrome-testing/src/Lib.hs, interpreted )
/Users/.../palindrome-testing/src/Lib.hs:1:1: warning: [GHC-85401] [-Wmissing-export-lists]
The export item ‘module Lib’ is missing an export list
|
1 | module Lib where
| ^
[2 of 4] Compiling Main ( /Users/.../palindrome-testing/app/Main.hs, interpreted )
[3 of 4] Compiling Paths_palindrome_testing ( /Users/.../palindrome-testing/.stack-work/dist/aarch64-osx/ghc-9.8.4/build/autogen/Paths_palindrome_testing.hs, interpreted )
Ok, three modules loaded.
Loaded GHCi configuration from /Users/.../.cache/stack/ghci-script/959789a9/ghci-script
ghci> isPalindrome "sam I mas"
True
ghci> :q
Leaving GHCi.
%