Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
From: "Dmitry Bely" <dmitry.bely@gmail.com>
To: "Caml List" <caml-list@inria.fr>
Subject: F# lightweight syntax for Ocaml with camlp4 - possible?
Date: Tue, 8 May 2007 02:26:08 +0400	[thread overview]
Message-ID: <90823c940705071526x87f78b4i74bc73b11ee9a890@mail.gmail.com> (raw)

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


             reply	other threads:[~2007-05-07 22:26 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-05-07 22:26 Dmitry Bely [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=90823c940705071526x87f78b4i74bc73b11ee9a890@mail.gmail.com \
    --to=dmitry.bely@gmail.com \
    --cc=caml-list@inria.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox