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 #2

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

Lab 4 #2

BertLisser opened this issue Oct 8, 2018 · 0 comments

Comments

@BertLisser
Copy link

BertLisser commented Oct 8, 2018

Exercise 2

integerSetGeneratorFromScratch :: IO (Set Int)
integerSetGeneratorFromScratch = do
    n <- getRandomNatural
    xs <- getRandomIntegers maxNatural
    return (Set (nub xs))

-- Time spent: 1:15

instance (Arbitrary a, Eq a) => Arbitrary (Set a) where 
    arbitrary = do
        xs <- arbitrary
        return (Set (nub xs))

The function sort is missing in return (Set (nub xs)).
It must become: return (Set (sort(nub xs)))

Exercise 6

-- Transitive closure
trClos :: Ord a => Rel a -> Rel a
trClos r = until (\s -> tr s == s) tr r
    where tr r = sort (nub ((r @@ r) ++ r))

will be go wrong in the first step
Solution:

-- Transitive closure
trClos' :: Ord a => Rel a -> Rel a
trClos' r = until (\s -> tr s == s) tr r
    where tr r = sort (nub ((r @@ r) ++ r))
trClos :: Ord a => Rel a -> Rel a
trClos r =  trClos' (sort r)

Ex 8

prop_ClosuresDifference :: Rel Int -> Bool
prop_ClosuresDifference r = symClos (trClos r') == trClos (symClos r') 
    where r' = nub r

the test defined in prop_ClosuresDifference must become

sort(symClos (trClos r') )==sort(trClos (symClos r') )
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