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

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

Lab 4 #4

BertLisser opened this issue Oct 8, 2018 · 0 comments

Comments

@BertLisser
Copy link

BertLisser commented Oct 8, 2018

Exercise 5

type Rel a = [(a,a)]

symClos :: Ord a => Rel a -> Rel a
symClos []         = []

symClos :: Ord a => Rel a -> Rel a
symClos ((x,y):xs) = (nub $ sort $ (y,x):(x,y):(symClos xs))

Better and cheaper

symClos' []         = []
symClos' ls@((x,y):xs) = (y,x):ls
symClos xs = nub $ sort symclos' xs

Exercise 7
Nice readable documentation by using mathematical symbols!
{-
trClos:
Test properties:
∀ x, y, z: xSy, ySz => xSz
R ⊆ S
∀ S' ⊂ S: S' is not a transitive closure of R
-}
The following function is not a good idea.

prop_TrClosSmallest r = isSmallest $ trClos r
        where
            isSmallest s = r ⊆ s && isTransitive s && (not . hasSmaller) s
            hasSmaller []       = False
            hasSmaller [x]      = isSmallest []
            hasSmaller (x:y:xs) = isSmallest (x:xs) && isSmallest (y:xs)
            types = (r :: Rel Int)

Why not

prop_TrClosSmallest r  = not (Any (\x -> not( isTransitive r\\ [x] )  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