Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lab 3: Ex 4 #4

Open
BertLisser opened this issue Sep 27, 2017 · 0 comments
Open

Lab 3: Ex 4 #4

BertLisser opened this issue Sep 27, 2017 · 0 comments

Comments

@BertLisser
Copy link

BertLisser commented Sep 27, 2017

genCnj :: Int -> Gen Form
genCnj i = do n <- choose(2, i)
              f <- vectorOf n (genForm (i `div` n))
return (Cnj f)

Too complicated and to restricted. Simpler solution by using n of sized.
So an improvment will be

genCnj :: Int -> Gen Form
genCnj n = do 
              f <- vectorOf n (genForm (n `div` 2))
return (Cnj f)

And

-- Exercise 4 - Erik van Scharrenburg
instance Arbitrary Form where
  arbitrary = sized genForm

genForm :: Int -> Gen Form
genForm 0 = genProp
genForm 1 = genProp
genForm 2 = genProp
genForm i = oneof [genNeg   (i - 1),
                   genCnj   (i - 1),
                   genDsj   (i - 1),
                   genImpl  (i - 1),
                   genEquiv (i - 1)]

genProp :: Gen Form

Better

-- Exercise 4 - Erik van Scharrenburg
instance Arbitrary Form where
  arbitrary = sized genForm

genForm :: Int -> Gen Form
genForm 0 = genProp
genForm n = oneof [genNeg   n
                   genCnj   n,
                   genDsj   n,
                   genImpl  n,
                   genEquiv n]

genProp :: Gen Form

Well done (=9)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant