Skip to content

Instantly share code, notes, and snippets.

@folivetti

folivetti/Q205.hs

Created Jan 23, 2020
Embed
What would you like to do?
module Main where
import qualified Data.Set as S
-- hasMorph p m and hasMorph p n
isValid :: (a -> a -> Bool) -> (a -> a -> a) -> a -> a -> Bool
isValid f op x y = f p x && f p y
where p = x `op` y
-- (a)
divides :: Int -> Int -> Bool
divides m n = n `mod` m == 0
prodA = gcd 42 27
-- (b)
s1 = S.fromList "abc"
s2 = S.fromList "bdc"
prodB = S.intersection s1 s2
-- (c)
prodC = True && False
implies True True = True
implies True False = False
implies False True = True
implies False False = True
main = do
putStr "The product of 42 and 27 is "
print prodA
putStr "Is there a morphism from (a,b) -> a and (a,b) -> b? "
print $ isValid divides gcd 42 27
putStr "The product of abc and bcd is "
print prodB
putStr "Is there a morphism from (a,b) -> a and (a,b) -> b? "
print $ isValid S.isSubsetOf S.intersection s1 s2
putStr "The product of True and False is "
print prodC
putStr "Is there a morphism from (a,b) -> a and (a,b) -> b? "
print $ isValid implies (&&) True False
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.