Skip to main content

  | मौसम…

411 समाचार
Public archive edition · Attributed source reporting with original dates · AI drafts are excluded

411 REFERENCE · Wikibooks

Haskell/Solutions/Variables and functions

Reference material by Wikibooks contributors. This retains its source identity and is not 411 news reporting.

Explain how GHCi evaluates quadruple 5. Define a function that subtracts 12 from half its argument. quadruple x = double (double x) quadruple 5 = double (double 5) quadruple 5 = double 10 quadruple 5 = 20 subtractHalf x = x / 2 - 12 Write a function to calculate the volume of a box. Approximately how many stones are the famous pyramids at Giza made up of? Use GHCi for your calculations. volumeBox w h d = w * h * d One approach for the Giza problem is starting from the pyramid volume and the estimated stone volume. Using general functions for the task, that might look like this in 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 Write a function to calculate the volume of a cylinder. volumeCylinder r h = h * area r