【发布时间】:2020-05-20 04:48:03
【问题描述】:
我开始学习 F#,但对类型问题感到困惑。 对于上下文,我正在搜索给定包含半径、高度的元组列表的圆柱体的最大体积
我得到一个“这个表达式应该有'float'类型,但是当我调用recMax hd t1时这里有'float*float'类型
let CylinderVolume ((radius, height) : float*float) =
height * System.Math.PI * radius * radius
let maxCylinderVolume list : float =
match list with
| [] -> 0.0
| hd :: t1 ->
let rec recMax maxSoFar items =
match items with
| [] -> maxSoFar
| hd :: t1 ->
if (CylinderVolume hd) > maxSoFar then
recMax (hd) t1
else
recMax maxSoFar t1
recMax hd t1
【问题讨论】:
-
你想要最大音量,不应该是
recMax (CylinderVolume hd) t1吗?