I have a task of calculating the height of a logical expression (like a∧(b∨c)). I have an algorithm, however there is a mistake that causes 2 errors
this function application is partial
This expression has type int * int -> int * int but an expression was expected of type int I have no clue what I'm doing wrong? Below is the code snippet:
let height fg = let rec aux acc = function | Bot -> acc+1 | Top -> acc+1 | Atome x -> acc+1 | Imp(f, g) -> max(aux(acc+1)f, aux(acc+1)g) | And(f, g) -> max(aux(acc+1)f, aux(acc+1)g) | Or(f, g) -> max(aux(acc+1)f, aux(acc+1)g) in acc 0;;
Thank's a lot in advance.
As noted in comments, you're passing a tuple to max
rather than two curried arguments.
let height f g =
let rec aux acc = function
| Bot -> acc+1
| Top -> acc+1
| Atome x -> acc+1
| Imp (f, g) -> max (aux (acc+1) f) (aux (acc+1) g)
| And (f, g) -> max (aux (acc+1) f) (aux (acc+1) g)
| Or (f, g) -> max (aux (acc+1) f) (aux (acc+1) g)
in
acc 0
While you can write functions that take multiple arguments as a single tuple, this is not idiomatic in OCaml.
let f x y = ...
Vs.
let f (x, y) = ...
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.