You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
-- This function creates a random set using quickcheck
-- with lowerbound a, upperbound b and maximum length n.
getRandomSetQC :: Int -> Int -> Int -> IO (Set Int)
getRandomSetQC n a b = do
l <- getRandomListQC n a b
let r = list2set l
return r
-- This function creates a random list using generate and show
-- from quickcheck with lowerbound a, upperbound b and length n.
getRandomListQC :: Int -> Int -> Int -> IO ([Int])
getRandomListQC n a b = sequence (replicate n (generate (choose (a, b))))
You have to define an instance of arbitrary belonging to the type Set.
Ex. 6
This is wrong code. temp is not sorted and with duplicates.
-- Transitive closure of relation, sorted and without duplicates
trClos :: Ord a => Rel a -> Rel a
trClos xs
| xs /= temp = trClos temp
| otherwise = xs
where temp = (xs `union` concat [ concat [ ([a] @@ [b]) | a <- xs, a /= b] | b <- xs])
Solution
trClos :: Ord a => Rel a -> Rel a
trClos xs
| xs /= temp = trClos temp
| otherwise = xs
where temp = (sort.nub) (xs `union` concat [ concat [ ([a] @@ [b]) | a <- xs, a /= b] | b <- xs])
The text was updated successfully, but these errors were encountered:
Ex. 2
This is no preparation for using
quickCheck
You have to define an instance of
arbitrary
belonging to the typeSet
.Ex. 6
This is wrong code.
temp
is not sorted and with duplicates.Solution
The text was updated successfully, but these errors were encountered: