-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Description
Ex. 6
trClos :: Ord a => Rel a -> Rel a
trClos xs = keepSearching (sort.nub) xs
keepSearching :: Ord a => Rel a -> Rel a -> Rel a
keepSearching rel1 rel2 = if (nub(rel1++(rel1@@rel2)) == nub(rel1++rel2))
then nub(rel1++rel2)
else keepSearching (rel1++(rel1@@rel2)) rel2
Too expensive. It does too much steps. Better:
trClos :: Ord a => Rel a -> Rel a
trClos xs = keepSearching xs xs
keepSearching :: Ord a => Rel a -> Rel a
keepSearching rel1 = if ((sort.nub)(rel1++(rel1@@rel1)) == rel1)
then rel1
else keepSearching ((sort.nub) (rel1++(rel1@@rel1)))
Ex. 7
-- Test trClos
prop_trClos :: Ord a => Rel a -> Bool
prop_trClos r = let rclos = trClos r
transitiveChecks :: [Bool]
transitiveChecks = [ ((a, c) `elem` rclos) | (a, b) <- rclos, (c, d) <- rclos, b == c ]
in (nub r) `isSublist` (nub rclos) -- Check if r is subset of rclos
&& foldr (&&) True transitiveChecks -- Check transitive property of rclos
must become
prop_trClos :: Ord a => Rel a -> Bool
prop_trClos r = let rclos = trClos r
transitiveChecks :: [Bool]
transitiveChecks = [ ((a, d) `elem` rclos) | (a, b) <- rclos, (c, d) <- rclos, b == c ]
in (nub r) `isSublist` (nub rclos) -- Check if r is subset of rclos
&& foldr (&&) True transitiveChecks -- Check transitive property of rclos
Metadata
Metadata
Assignees
Labels
No labels