Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow sequential lets without "in" also in expressions #5198

Closed
vicuna opened this issue Dec 17, 2010 · 2 comments
Closed

Allow sequential lets without "in" also in expressions #5198

vicuna opened this issue Dec 17, 2010 · 2 comments

Comments

@vicuna
Copy link

vicuna commented Dec 17, 2010

Original bug ID: 5198
Reporter: lealanko
Status: closed (set by @xavierleroy on 2015-12-11T18:24:15Z)
Resolution: won't fix
Priority: normal
Severity: feature
Category: ~DO NOT USE (was: OCaml general)

Bug description

This is the classic ocaml syntax pet peeve. Might as well make a feature request out of it, so if it gets rejected, there's an "official record" of it and no one need bother with it ever again.

Other syntax issues aside, the most annoying ocamlism is the syntax for sequential lets, particularly the tailing "in". If one writes in an expression context:

let foo = bar baz quux in
let drokk = fnord fnarp zool in
...

then the tailing "in" is visually indistinguishable from the preceding arguments if they are short variable names, and one is heavily dependent on syntax highlighting to clarify the structure of the program. Alternatively, if one writes

let foo = bar baz quux
in let drokk = fnord fnarp zool
in ...

then the structure is clearer, but the indentation is inconsistent. Of course one could give extra indentation to the first line, but that would require special tool support and it would look kind of weird. The neatest solution currently is:

let foo = bar baz quux
in
let drokk = fnord fnarp zool
in
...

but that obviously wastes space quite a bit.

It is strange that this sequential let construct, though ubiquitous in all ocaml code, is so cumbersome, whereas "let ... and ..." has a very nice syntax, although it is only needed in special circumstances where one needs to shadow several variable names at once.

There is an obvious solution to this problem: just provide special support for sequential lets by allowing a let to directly follow a preceding let without an intervening "in":

let foo = bar baz quux
let drokk = fnord fnarp zool
in ...

This shouldn't cause any syntax ambiguities because the very same syntax for lets is already supported in module bodies!

I'm inclined to suspect that this option has already been intentionally rejected for some reason because it is so obvious, but one can always hope. All the other syntax issues in ocaml are minor in comparison to this one.

@vicuna
Copy link
Author

vicuna commented May 17, 2011

Comment author: @damiendoligez

This would be quite hard to parse with a yacc grammar because you need to look ahead all the way to the "in" keyword in order to differentiate between (as a module body)
let a = 1 let b = 1
and
let a = 1 let b = 1 in 1

@vicuna
Copy link
Author

vicuna commented Oct 7, 2013

Comment author: @damiendoligez

This shouldn't cause any syntax ambiguities because the very same syntax for lets is already supported in module bodies!

In fact it would be ambiguous precisely because of this. Consider, in a module body:

let x = 1 let y = 2 in x + y;;

Currently, this means:
let x = 1;; let y = 2 in x + y;;

With your proposal, it might also mean:
let x = 1 in let y = 2 in x + y;;

Now write:
let x = 10;; let x = 1 let y = 2 in x + y;; print_int x;;
you don't know if it's going to print 10 or 1.

@vicuna vicuna closed this as completed Dec 11, 2015
bobzhang added a commit to rescript-lang/ocaml that referenced this issue Jul 1, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant