user2874757
user2874757

Reputation: 137

OCAML how works an 'in'

I would like to ask You abuot key word 'in'. What is destination of it ? When we use it ? What does it do ? Is there any recommended way to use it ? What about efficiency ? Thanks in advance.

Upvotes: 1

Views: 91

Answers (2)

Jackson Tale
Jackson Tale

Reputation: 25812

Simply say, in is to tell the "range" or "domain" of a binding.

let x = 5 in
let y = x * x in
x * y

The first in tells x=5 is effective in the following let y = x * x in x * y, the second in tells that y = x * x is effective in x*y

Upvotes: 0

sepp2k
sepp2k

Reputation: 370102

The keyword in is used as part of the let <binding> in <expression> syntax.

When we use it ?

We use it whenever we use a let expression.

What does it do ?

It separates the binding from the expression in which the binding will hold.

Is there any recommended way to use it ?

The recommended way to use it is as part of a let expression, between the binding and the expression. There is no other way to use it.

What about efficiency ?

Its function is merely syntactically. Therefore it has no bearing on efficiency.

Upvotes: 2

Related Questions