Could you please answer this questions: For this two exercises, develop and test
ID: 3875771 • Letter: C
Question
Could you please answer this questions:
For this two exercises, develop and test a Haskell function :
1).The time of day can be represented by a tuple (hours,minutes,m) where m indicates either "AM" or "PM". Develop a Boolean Haskell function comesBefore that takes two time-of-day tuples and determines whether the first is an earlier time than the second. (Note: Consider midnight and noon.)
2)Develop a Haskell function
such that minf g returns the smallest integer m such that 0 <= m <= 10000000 and g m == 0 (if such an integer exists).
Explanation / Answer
1)
comesBefore :: (Int,Int,String) -> (Int,Int,String) -> Bool
comesBefore (a1,b1,c1) (a2,b2,c2) | (a1<a2) = True
| (a1>a2) = False
| (a1==a2) && (b1<b2) = True
| (a1==a2) && (b1>b2) = False
| (a1==a2) && (b1==b2) && (c1=="AM") && (c2=="PM") = True
| (a1==a2) && (b1==b2) && (c1=="PM") && (c2=="AM") = False
main= print (comesBefore (4,20,"AM") (4,15,"AM"))
2)
minf :: (Int -> Int) -> Int
g :: Int -> Int
-- Assume
g x = x%2
minf g x| if g(x)==0 && x>0 && x<10000000 then x