Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
* 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

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