57.5k views
1 vote
True or False: the then branch and the else brach may have different types in OCaml

User Soleshoe
by
8.0k points

1 Answer

3 votes

Final answer:

In OCaml, the then branch and the else branch must yield values of the same type, as it is a statically typed language, making the statement False.

Step-by-step explanation:

The statement that the then branch and the else branch may have different types in OCaml is False. In OCaml, it's a type error if the then and else branches of a conditional expression yield values of different types. This is because OCaml is a statically typed language, and the type of an expression must be known at compile-time. Therefore, both branches must result in values of the same type for the overall conditional expression to have a well-defined type.

User Jenee
by
7.4k points