Define a function
sign
which given an integer returns 1 if it is positive, -1 if it is negative and 0 if it is zero.
my solutions
solution 1
let sign i = if i!=0 then (if i<0 then -1 else 1) else 0;;
solution 2
let sign x = if x = 0 then 0 else if x<0 then -1 else 1;;
It doesn't work for negative numbers but it works for positive numbers and zero.
I receive the following error
Error: This expression has type int -> int but an expression was expected of type int