#1 Rewrite the following code in Haskell : if ( books < 1) numCoupons = 0; else
ID: 3640181 • Letter: #
Question
#1 Rewrite the following code in Haskell :
if ( books < 1)
numCoupons = 0;
else if (books < 3)
numCoupons = 1
else if (books < 5)
numCoupons = 2
else
numcoupons = 3;
-----------------------------------------------
#2 Write a Haskell function that converts Fahrenheit to Celsius (formula is F-32 * 5/9 = C)
Explanation / Answer
PS: Please rate 2. newtype Fahrenheit = Fahrenheit Float deriving (Eq, Ord, Show, Num, Fractional) newtype Celsius = Celsius Float deriving (Eq, Ord, Show, Num, Fractional) far2cel :: Fahrenheit -> Celsius far2cel (Fahrenheit far) = Celsius $ (5 / 9) * (far - 32) 1. is pretty straight forward. Here is a reference - http://en.wikibooks.org/wiki/Haskell/Control_structures#if_Expressions
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.