試試這個:
cubicQ a b c = (3*a*c - b**2)/(9*a**2)
cubicR a b c d = (9*a*b*c - 27*(a**2)*d-2*b**3)
cubicS q r = (r+ (q**3+r**2)**(1/2))**(1/3)
f a b c d = cubicS (cubicQ a b c) (cubicR a b c d)
main = do print $ f 1 2 3 4
或:
cubicS a b c d = (r+ (q**3+r**2)**(1/2))**(1/3)
where q = cubicQ a b c
r = cubicR a b c d
或:
cubicS a b c d =
let q = cubicQ a b c
r = cubicR a b c d
in (r+ (q**3+r**2)**(1/2))**(1/3)
看到:
cubicQ :: Float -> Float -> Float -> Float
cubicQ a b c = (3*a*c - b**2)/(9*a**2)
cubicR :: Float -> Float -> Float -> Float -> Float
cubicR a b c d = (9*a*b*c - 27*(a**2)*d-2*b**3)
cubicS :: Float -> Float -> Float -> Float -> Float
cubicS a b c d =
let q = cubicQ a b c
r = cubicR a b c d
in
(r+ (q**3+r**2)**(1/2))**(1/3)
main = do print $ cubicS 1.1 2.2 3.3 4.4
輸出:
9.736999e-2
,如果你限制在cubicS
是cubicS: Float -> Float -> Float
:
cubicQ a b c = (3*a*c - b**2)/(9*a**2)
cubicR a b c d = (9*a*b*c - 27*(a**2)*d-2*b**3)
cubicS q r = (r+ (q**3+r**2)**(1/2))**(1/3)
cureS a b c d = cubicS q r
where q = cubicQ a b c
r = cubicR a b c d
main = do print $ cureS 1.1 2.2 3.3 4.4
如果'cubicS'具有類型'浮法 - >浮動 - > Float',你只需要傳遞兩個參數,都是'Float'類型。不是功能,不是整數,不是列表,不是奶油芝士百吉餅。 –