0

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

  1. this function application is partial

  2. 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 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;;
    

Thank's a lot in advance.

Chris
  • 26,361
  • 5
  • 21
  • 42
PRO grmr
  • 1
  • 1

1 Answers1

0

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) = ...
Chris
  • 26,361
  • 5
  • 21
  • 42