* F# lightweight syntax for Ocaml with camlp4 - possible?
@ 2007-05-07 22:26 Dmitry Bely
2007-05-07 22:36 ` [Caml-list] " Chris King
2007-05-07 23:43 ` Daniel Bünzli
0 siblings, 2 replies; 6+ messages in thread
From: Dmitry Bely @ 2007-05-07 22:26 UTC (permalink / raw)
To: Caml List
Some times ago F# team has introduced a new Caml syntax option called
"lightweight". From the F# manual:
http://research.microsoft.com/fsharp/manual/lexyacc.aspx
[...]
F# supports the optional use of lightweight syntax through the use of
whitespace to make indentation significant. At the time of this
release this is an experimental feature, though it is assumed that its
use will become widespread. The indentation-aware syntax option is a
conservative extension of the explicit language syntax, in the sense
that it simply lets you leave out certain tokens such as in and ;; by
having the parser take indentation into account. This can make a
surprising difference to the readability of code.
[...]
Basic rules by example
// Without the light syntax option
// 'done' is required
let FunctionSample() =
let tick x = printf "tick %d\n" x in
let tock x = printf "tock %d\n" x in
let choose f g h x =
if f x then g x else h x in
for i = 0 to 10 do
choose (fun n -> n%2 = 0) tick tock i
done;
printf "done!\n"
// When the light syntax option is
// enabled 'done' is optional and the scope of
// structured constructs such as match, for, while
// and if/then/else is determined by indentation.
#light
let FunctionSample() =
let tick x = printf "tick %d\n" x
let tock x = printf "tock %d\n" x
let choose f g h x =
if f x then g x else h x
for i = 0 to 10 do
choose (fun n -> n%2 = 0) tick tock i
printf "done!\n"
[end of quote]
Could the same idea be implemented for Ocaml with Camlp4? Can it use
an indentation level while parsing?
I realize that the third syntax will be 'too much' but it really seems
to be quite useful...
- Dmitry Bely
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [Caml-list] F# lightweight syntax for Ocaml with camlp4 - possible?
2007-05-07 22:26 F# lightweight syntax for Ocaml with camlp4 - possible? Dmitry Bely
@ 2007-05-07 22:36 ` Chris King
2007-05-10 15:24 ` Nicolas Pouillard
2007-05-07 23:43 ` Daniel Bünzli
1 sibling, 1 reply; 6+ messages in thread
From: Chris King @ 2007-05-07 22:36 UTC (permalink / raw)
To: Dmitry Bely; +Cc: Caml List
On 5/7/07, Dmitry Bely <dmitry.bely@gmail.com> wrote:
> Could the same idea be implemented for Ocaml with Camlp4? Can it use
> an indentation level while parsing?
It has been... http://people.csail.mit.edu/mikelin/ocaml+twt/
But it doesn't use camlp4 (since camlp4 can't modify the lexer to
handle tabs specially).
- Chris
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [Caml-list] F# lightweight syntax for Ocaml with camlp4 - possible?
2007-05-07 22:36 ` [Caml-list] " Chris King
@ 2007-05-10 15:24 ` Nicolas Pouillard
0 siblings, 0 replies; 6+ messages in thread
From: Nicolas Pouillard @ 2007-05-10 15:24 UTC (permalink / raw)
To: Chris King; +Cc: Dmitry Bely, Caml List
On 5/8/07, Chris King <colanderman@gmail.com> wrote:
> On 5/7/07, Dmitry Bely <dmitry.bely@gmail.com> wrote:
> > Could the same idea be implemented for Ocaml with Camlp4? Can it use
> > an indentation level while parsing?
>
> It has been... http://people.csail.mit.edu/mikelin/ocaml+twt/
> But it doesn't use camlp4 (since camlp4 can't modify the lexer to
> handle tabs specially).
This is somewhat different in the new version of Camlp4 even if one
cannot dynamically extend the default lexer.
1/ One can now change a Camlp4 module by another, since the
implementation is functorized.
2/ The default lexer now keeps all bits of the input including layout
information.
3/ One can setup a custom token filter, that can handle the
indentation, and then drop the layout information (The default filter
drops layout information).
Best regards,
--
Nicolas Pouillard
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [Caml-list] F# lightweight syntax for Ocaml with camlp4 - possible?
2007-05-07 22:26 F# lightweight syntax for Ocaml with camlp4 - possible? Dmitry Bely
2007-05-07 22:36 ` [Caml-list] " Chris King
@ 2007-05-07 23:43 ` Daniel Bünzli
2007-05-08 1:28 ` Jon Harrop
1 sibling, 1 reply; 6+ messages in thread
From: Daniel Bünzli @ 2007-05-07 23:43 UTC (permalink / raw)
To: Caml List
Le 8 mai 07 à 00:26, Dmitry Bely a écrit :
> I realize that the third syntax will be 'too much' but it really
> seems to be quite useful...
In a language where you don't enclose function arguments in parens I
think this is really a bad idea, it makes the code more confusing
than readable, especially if you try to code with a line width of 80
columns.
Daniel
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [Caml-list] F# lightweight syntax for Ocaml with camlp4 - possible?
2007-05-07 23:43 ` Daniel Bünzli
@ 2007-05-08 1:28 ` Jon Harrop
2007-05-08 4:12 ` skaller
0 siblings, 1 reply; 6+ messages in thread
From: Jon Harrop @ 2007-05-08 1:28 UTC (permalink / raw)
To: caml-list
On Tuesday 08 May 2007 00:43, Daniel Bünzli wrote:
> In a language where you don't enclose function arguments in parens I
> think this is really a bad idea, it makes the code more confusing
> than readable, especially if you try to code with a line width of 80
> columns.
As a hardcore OCamler, I must say that I had thought the #light syntax in F#
to be morally repugnant. However, now that I've forced myself to actually use
it, I'm finding it to be very useful indeed.
Perhaps the single most important reason why the #light syntax is useful stems
from the way the F# Visual Studio add-in allows you to execute lines or
blocks of code in a running interactive session. I'd love to see something
similar for OCaml but, until then, I don't think the #light syntax would have
quite the bite for OCaml that it does for F#.
--
Dr Jon D Harrop, Flying Frog Consultancy Ltd.
The F#.NET Journal
http://www.ffconsultancy.com/products/fsharp_journal/?e
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2007-05-10 15:24 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-05-07 22:26 F# lightweight syntax for Ocaml with camlp4 - possible? Dmitry Bely
2007-05-07 22:36 ` [Caml-list] " Chris King
2007-05-10 15:24 ` Nicolas Pouillard
2007-05-07 23:43 ` Daniel Bünzli
2007-05-08 1:28 ` Jon Harrop
2007-05-08 4:12 ` skaller
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox