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 4 #3

Open
BertLisser opened this issue Oct 9, 2018 · 0 comments
Open

Lab 4 #3

BertLisser opened this issue Oct 9, 2018 · 0 comments

Comments

@BertLisser
Copy link

BertLisser commented Oct 9, 2018

Ex. 2

instance Arbitrary a => Arbitrary (Set a) where
    arbitrary = fmap Set arbitrary

Is wrong because the array belonging to

{-- START OF LECTURE CODE --}
{-- Sets implemented as ordered lists without duplicates --}

newtype Set a = Set [a] deriving (Eq,Ord)

must have no duplicates and must be ordered.
A solution is:

instance (Eq a,  Ord a, Arbitrary a) => Arbitrary (Set a) where
    arbitrary = fmap Set (liftM (sort.nub) arbitrary)

Ex. 3
Then you don't need to define 'testIntIntersection' and 'quickCheck' on a list of Integers
but instead directly

quickCheckIntersection = verboseCheck (testIntersection::(Set Int->Set Int->Bool))

and so on.

Ex 7

isTransitive :: Eq a => Rel a -> Bool
isTransitive xs = and [ elem(a,c) xs | (a,b) <- xs, (c,d) <- xs, b == c ]

is wrong. Must become

isTransitive :: Eq a => Rel a -> Bool
isTransitive xs = and [ elem(a,d) xs | (a,b) <- xs, (c,d) <- xs, b == c ]
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