Skip to content

Instantly share code, notes, and snippets.

@folivetti
Created January 23, 2020 21:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save folivetti/e0ded9e8469388b6d00676d394a92c0d to your computer and use it in GitHub Desktop.
Save folivetti/e0ded9e8469388b6d00676d394a92c0d to your computer and use it in GitHub Desktop.
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