Last active
April 13, 2021 03:19
-
-
Save igrep/805a78ae94b6d4f57c077e130e82756b to your computer and use it in GitHub Desktop.
唯一let ... inを使いたくなる瞬間をdoのletでどうにかする
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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