caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: "David Allsopp" <dra-news@metastack.com>
To: "'Caml-list List'" <caml-list@inria.fr>
Subject: RE: [Caml-list] If OCaml were a car
Date: Tue, 21 Aug 2007 09:05:33 +0100	[thread overview]
Message-ID: <005a01c7e3ca$0ce14fa0$6a7ba8c0@treble> (raw)
In-Reply-To: <20070819170704.GA10089@furbychan.cocan.org>

> It's not likely that the syntax can be changed (how is the revised
> syntax doing lately?) but there is one error message which could be
> fixed.  When I worked at Merjis a colleague got frustrated to the
> point of virtually giving up the language at the error message "Foo
> makes inconsistent assumptions over Bar"[1].  It is literally useless:
> it does not describe what it means, what files are involved which are
> inconsistent, what their MD5 sums are or should be, and lastly it
> doesn't say how to fix the problem (which generally involves
> recompiling libraries).

I'm not sure I'd classify this as the "worst" message the compiler gives -
when I see that it tells me that my Makefile dependencies are broken (if
Bar.cmi is part of my project) or that I've updated a library (if Bar.cmi is
from something else) and either way that make clean; make will fix it for
now!

The error message on a missing "in" in a "let...in" block on the other hand
is the one that drives me up the wall...

(* first function *)
let f x = (* definition of f *)
in
  let g x = (* definition of g *)
  (* etc, etc *)

(* next function *)
let h x = (* definition of *)

Here, O'Caml helpfully tells me that there's a syntax error on line 7 which
is of course complete rubbish!! It may be easy to spot here, but I've
absent-mindedly missed the final part of a bigger function mid-development
(or after having to leave the code and come back to it) and had to spend
*ages* trying to find where the error is in larger ML files... in this
situation I'd really like a "the let on line 4 may be un-matched" guess
similar to that for mismatched parenthesis :o)

> I tell beginners that most code they write should be within a toplevel
> statement:
> 
>  let _ =
>     ...
>
> or (better):
>
>   let () =
>     ...

I'd go one further - and recommend that all top level statements are
function definitions (there's so rarely a need to use global "variables"...
it usually comes back to bite you at some point later). Then define a
function main () to do the "top level" part of your program (the concept of
"main" is generally clearer to someone coming to ML from a more mainstream
language) and finish the whole thing to give code like:

type t = Foo

let foo f = f ()

let bar _ = Foo

let main () = foo bar

(* One top-level statement to run the program *)
let _ = main (); ()

While I wouldn't bet my life on it, I've never found a need for ";;" at all
when coding this way and ";" always binds as you expect it to.


David


  parent reply	other threads:[~2007-08-21  8:05 UTC|newest]

Thread overview: 40+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-08-18 19:21 Richard Jones
2007-08-18 20:24 ` [Caml-list] " Jeff Meister
2007-08-18 21:32   ` Michael Vanier
2007-08-19 11:50     ` Daniel Bünzli
2007-08-19 11:59       ` Erik de Castro Lopo
2007-08-22  5:50         ` Luca de Alfaro
2007-08-22  8:13           ` Jon Harrop
2007-08-22  9:20             ` Jacques Garrigue
2007-08-24  2:54           ` Nathaniel Gray
2007-08-25 19:45             ` Oliver Bandel
2007-08-19 14:43       ` John Carr
2007-08-19 16:22         ` brogoff
2007-08-19 17:07         ` Richard Jones
2007-08-19 17:19           ` Stefano Zacchiroli
2007-08-22  6:04             ` Luca de Alfaro
2007-08-19 20:51           ` Vincent Hanquez
2007-08-21  8:05           ` David Allsopp [this message]
2007-08-21 18:33             ` Richard Jones
2007-08-19 20:30         ` Tom
2007-08-19 21:45           ` skaller
2007-08-20  3:37             ` Jon Harrop
2007-08-20  6:26               ` skaller
2007-08-20 10:00                 ` Joerg van den Hoff
2007-08-21 12:03                   ` Florian Hars
2007-08-20  6:54               ` skaller
2007-08-20 19:54       ` Oliver Bandel
2007-08-20 20:27         ` David Allsopp
2007-08-20 20:50           ` Ulf Wiger (TN/EAB)
2007-08-21 10:56             ` Joerg van den Hoff
2007-08-20 21:13           ` Oliver Bandel
2007-08-21  0:47         ` skaller
2007-08-21  9:51           ` Oliver Bandel
2007-08-21 10:30             ` skaller
2007-08-21 18:57               ` Richard Jones
2007-08-22  2:49                 ` skaller
2007-08-22 11:33                   ` Thomas Fischbacher
2007-08-21 14:46             ` Business Adoption of Ocaml [was Re: [Caml-list] If OCaml were a car] Robert Fischer
2007-08-21 15:09               ` Brian Hurt
2007-08-21 15:48           ` [Caml-list] If OCaml were a car brogoff
2007-08-19 18:15 [caml-list] " Mike Lin

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='005a01c7e3ca$0ce14fa0$6a7ba8c0@treble' \
    --to=dra-news@metastack.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;
as well as URLs for NNTP newsgroup(s).