In scala programming language, given I'll annotate an expression with some broader type and I provide an narrow value, my program is rejected:
scala> def x[A](): A = 8
<console>:11: error: type mismatch;
found : Int(8)
required: A
def x[A]() = 8: A
Whereas in ocaml, when I'll do the same, the program is accepted, but the type annotation of the expression is overriden by the type of narrower expression.
utop # let x (): 'a = 8 ;;
val x : unit -> int = <fun>
What is the difference between these type systems, that results in situation, where in one case the program is rejected whereas in the other it is accepted?