Mantis Bug Tracker

View Issue Details Jump to Notes ] Issue History ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0005198OCamlOCaml generalpublic2010-12-17 12:212013-10-07 16:31
Reporterlealanko 
Assigned To 
PrioritynormalSeverityfeatureReproducibilityN/A
StatusresolvedResolutionwon't fix 
PlatformOSOS Version
Product Version 
Target VersionFixed in Version 
Summary0005198: Allow sequential lets without "in" also in expressions
DescriptionThis 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.
TagsNo tags attached.
Attached Files

- Relationships

-  Notes
(0005904)
doligez (administrator)
2011-05-17 16:57

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
(0010440)
doligez (administrator)
2013-10-07 16:31

> 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.

- Issue History
Date Modified Username Field Change
2010-12-17 12:21 lealanko New Issue
2011-05-17 16:57 doligez Note Added: 0005904
2011-05-17 16:57 doligez Status new => acknowledged
2013-10-07 16:31 doligez Note Added: 0010440
2013-10-07 16:31 doligez Status acknowledged => resolved
2013-10-07 16:31 doligez Resolution open => won't fix


Copyright © 2000 - 2011 MantisBT Group
Powered by Mantis Bugtracker