SICP exercises in Haskell (Section 2.1.4)
-- Section 2.1.4
-- Exercise 2.7
type Interval = (Float, Float)
make_interval :: Float -> Float -> Interval
make_interval x y = (x, y)
upper_bound :: Interval -> Float
upper_bound = snd
lower_bound :: Interval -> Float
lower_bound = fst
-- Exercise 2.8
sub_interval :: Interval -> Interval -> Interval
sub_interval x y =
make_interval (lower_bound x - upper_bound y)
(upper_bound x - lower_bound y)
-- To be continued. :)
没有评论:
发表评论