2015-10-16 132 views
1

我在我的代码中有一个错误。你能帮助我吗,并告诉我如何使用函数,它在if语句中返回布尔值?OCaml。关于如果陈述

let pol a b c = 
    let p=(a+.b+.c)/.2.0 in sqrt(p*.(p-.a)*.(p-.b)*.(p-.c));; 

let test a b c = 
    (a+.b)>c &&(b+.c)>a &&(a+.c)>b 

let main a b c = 
    let w=test(a b c) in(
    if w 
    then pol (a b c) 
    else raise(Failure "Error"));; 

回答

2

至于我可以看到你的问题在您的通话poltest。你已经定义了这两个函数,以便它们有三个独立的参数,但是你将它们传递给一个表示奇怪函数调用的单个参数。

OCaml中的惯用函数调用没有括号:

# let f a b = a + b;; 
val f : int -> int -> int = <fun> 
# f 3 8;; 
- : int = 11 

你正在试图做更多的东西是这样的:

# f (3 8);; 
Error: This expression has type int 
     This is not a function; it cannot be applied. 

正如你所看到的,如果你写(3 8)你要求将3作为一个函数,应该通过8作为参数。您的代码中存在与(a b c)类似的问题。

+0

WOW。大。非常感谢!!! –