Haskell/解决方案/变量和函数
外观
练习 |
---|
|
quadruple x = double (double x)
quadruple 5 = double (double 5)
quadruple 5 = double 10
quadruple 5 = 20
subtractHalf x = x / 2 - 12
练习 |
---|
|
volumeBox w h d = w * h * d
解决吉萨问题的其中一种方法是从棱锥体积和估计的石头体积入手。使用通用函数完成此任务,这在 GHCi 中可能如下所示
Prelude> let volumeBox w h d = w * h * d -- Just as above. Prelude> let volumeSquarePyramid b h = b * b * h / 3 Prelude> volumeSquarePyramid 230.4 146.5 / volumeBox 1 1 1 2592276.48
练习 |
---|
|
volumeCylinder r h = h * area r