Copyright | (c) Eric Zoerner 2023 |
---|---|
License | BSD3 |
Maintainer | eric.zoerner@proton.me |
Safe Haskell | Safe-Inferred |
Language | GHC2021 |
Exercise 3.1
(a) (False || (True && False)) || True
:: Bool
(b) ((2 3) 4) == ((4 3) 2)
:: Bool
(c) ((7 - (5 / 4)) > 6) || (((2 ^ 5) - 1) == 31)
:: Bool
(d) 2 < 3 < 4
Not well formed: cannot operate on Bool with comparison operators.
(e) (2 < 3) || (3 < 4)
:: Bool
(f) 2 && 3 < 4
Not well formed: cannot operate on numeric types with logical && operator.
Exercise 3.2
Exercise 3.3
Exercise 3.4
bagFee :: Bool -> Int Source #
Returns 100
if the person is checking bags and 0
if not.
Implemented with if-then-else
.
bagFee2 :: Bool -> Int Source #
Returns 100
if the person is checking bags and 0
if not.
Implemented with pattern matching on the input.
Exercise 3.5
greaterThan50 :: Integer -> Bool Source #
Exercise 3.6
amazingCurve :: Int -> Int Source #
Double the score without going over 100
Exercise 3.7
>>>
:type bagFee False
bagFee False :: Int
>>>
bagFee False
0
Exercise 3.8
circleRadius :: Double Source #
circleRadius = 3.5
Exercise 3.9
How many functions with type Bool -> Bool
are there?
There are 4 Bool -> Bool
functions.
What would be good names for them?
alwaysFalse
, alwaysTrue
, identity
, and not
How many functions have type Bool -> Bool -> Bool
?
There are 16 Bool -> Bool -> Bool
functions.
Exercise 3.10
True || False && False