Skip to content

Instantly share code, notes, and snippets.

@igrep
Last active April 13, 2021 03:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save igrep/805a78ae94b6d4f57c077e130e82756b to your computer and use it in GitHub Desktop.
Save igrep/805a78ae94b6d4f57c077e130e82756b to your computer and use it in GitHub Desktop.
唯一let ... inを使いたくなる瞬間をdoのletでどうにかする
import Test.Hspec
import Test.Hspec.QuickCheck
import Test.QuickCheck
-- 従来、Hspecで個別のテストケースに対して Gen を定義したい場合、
-- いちいち違う名前を付けるのが面倒なので let ... in で g (あるいはgen)という名前を使い回していたが、
-- 別にそれもdoの中のletで解決できることが発覚した。
main = hspec $ do
-- let ... inを使った場合
let g = arbitrary :: Gen Int
in prop "int" $ forAll g $ \val -> do
val `shouldBe` undefined
let g = arbitrary :: Gen Char
in prop "char" $ forAll g $ \val -> do
val `shouldBe` undefined
-- doの中のletを使った場合
do
let g = arbitrary :: Gen Int
prop "int" $ forAll g $ \val -> do
val `shouldBe` undefined
do
let g = arbitrary :: Gen Char
prop "char" $ forAll g $ \val -> do
val `shouldBe` undefined
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment