Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
From: "David Allsopp" <dra-news@metastack.com>
To: "'Brighten Godfrey'" <pbg@cs.berkeley.edu>
Cc: "'OCaml List'" <caml-list@yquem.inria.fr>
Subject: RE: [Caml-list] Value shadowing (tangent)
Date: Wed, 13 Aug 2008 12:04:26 +0100	[thread overview]
Message-ID: <583C0D4BF86A484BACB5D503F09037F1@countertenor> (raw)
In-Reply-To: <1C96BA4C-8E65-44AA-96CD-C1CA399635E2@cs.berkeley.edu>

> Going off on a tangent here...

Indeed :o)

> > let lst = [5; 4; 3; 2; 1; 0; -1; -2; -3; -4; -5]
> > in
> >   let filter = List.filter (fun x -> x > 0)
> >   in
> >     let double = List.map (fun x -> -2 * x)
> >     in
> >       let sort = List.sort compare
> >       in
> >         (sort $$ double $$ filter) lst
>
> I've seen little of other people's OCaml code, so out of curiosity,  
> do you or others actually write code formatted like the above, as  
> opposed to the more compact and (I think) readable
>
>      let lst = [5; 4; 3; 2; 1; 0; -1; -2; -3; -4; -5] in
>      let filter = List.filter (fun x -> x > 0) in
>      let double = List.map (fun x -> -2 * x) in
>      let sort = List.sort compare in
>      (sort $$ double $$ filter) lst

I similarly learned OCaml without reference to anyone else's code - I find
the indentation invaluable when reading the code for spotting the scope. I
would normally have written the above as

let lst = [5; 4; 3; 2; 1; 0; -1; -2; -3; -4; -5]
and filter = List.filter (fun x -> x > 0)
and double = List.map (fun x -> -2 * x)
and sort = List.sort compare
in
  (sort $$ double $$ filter) lst

Which is actually less to type than yours but I was adapting the previous
let lst = .. let lst = .. which is why I ended up with a very indented
version in my previous post.

I've not seen it anywhere else but then I haven't looked!

<irrelevance>
I don't know how the OCaml compiler actually implements displays, but the
"quick" approach means that using let .. and .. in instead of nested lets
will compile faster as name resolution will be faster :o)
</irrelevance>


David


  reply	other threads:[~2008-08-13 11:29 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-08-13  8:54 Value shadowing David Allsopp
2008-08-13  9:15 ` [Caml-list] " Brighten Godfrey
2008-08-13  9:56   ` David Allsopp
2008-08-13 10:49     ` [Caml-list] Value shadowing (tangent) Brighten Godfrey
2008-08-13 11:04       ` David Allsopp [this message]
2008-08-13 11:04       ` Brighten Godfrey
2008-08-13 11:17         ` Daniel Bünzli
2008-08-13 23:05           ` Stefano Zacchiroli
2008-08-13 23:33             ` Daniel Bünzli
2008-08-13 11:05       ` Vincent Hanquez
2008-08-16 20:02         ` Pierre Etchemaïté
2008-08-17  8:07           ` David Allsopp
2008-08-17 10:28             ` Pierre Etchemaïté
2008-08-13 10:33   ` [Caml-list] Value shadowing Jim Farrand
2008-08-13 10:12 ` Richard Jones
2008-08-13 11:04   ` David Allsopp
2008-08-13 12:26     ` blue storm
2008-08-13 15:03     ` Mauricio Fernandez
2008-08-13 11:50 ` blue storm

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=583C0D4BF86A484BACB5D503F09037F1@countertenor \
    --to=dra-news@metastack.com \
    --cc=caml-list@yquem.inria.fr \
    --cc=pbg@cs.berkeley.edu \
    /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