Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

`or` and `&` in OCaml

Tags:

ocaml

In OCaml, the infix operators or and & are defined as synonyms for || and &&, resp. I like the first group of operators because they are a little easier to type, and they make me think I'm learning something different from conventional languages.

Unfortunately, both or and & are marked as deprecated in the manual. I'd like to know

  1. when this started, and
  2. why this is so.

If the designers of OCaml have wrote a rationale for this design decision, I'd like to know where it is located. I'd appreciate for your help.

As a side note, here's what I thought:

Argument 1. || and && are more friendly to former programmers of C and its descendants.

Counter-argument 1. OCaml is in few ways similar to C. It makes little sense to make it look like C in this particular regard only.

Argument 2. It is more desirable to have similar symbols for both conjunction and disjunction.

Counter-argument 2. In natural languages, we only had a special symbol, &, for conjunction and not for disjunction, and we were happy with that for centuries. Besides, some textbooks in logic, including Mathematical Logic by Shoenfield, use entirely different symbols for disjunction and conjunction, viz., & and ∨.

like image 579
Pteromys Avatar asked Mar 19 '14 01:03

Pteromys


People also ask

What is the difference between and/or and or?

And is used to connect or join two or more phrases, words, sentences , etc. Or is used to connect two or more possibilities, options, or alternatives . Two conjunctions ─ and as well as or ─ are a part of almost every sentence. Can you imagine how vague and ambiguous sentences would be without these conjunctions?

Does and/or mean both?

According to the legal commentators, when used together with “and,” the word “or” usually includes “and” and the “and/or” phrase means “either or both of.” Inclusion of the “/” would not have corrected any error, ambiguity or confusion already inherent in the use of the “and” “or” conjunctive-disjunctive.

What does it mean if I put and or?

Definition of and/or —used as a function word to indicate that two words or expressions are to be taken together or individually language comprehension and/or production— David Crystal.

Is and/or grammatically correct?

Please do not use "and/or" in either formal or informal writing. In common English, the "or" is a "non-exclusive or" which means "either A or B, or A and B". When I say "I can have a banana OR I can have coffee" then I am also OK with having both.


1 Answers

It was marked as deprecated in 2001.

I am not aware of any design rationale for this, probably C similarity was the main driving point. Also, or and & are keywords in jocaml - that might have been one of the reasons to discourage their use in regular OCaml.

like image 104
ygrek Avatar answered Sep 18 '22 00:09

ygrek