caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: skaller <skaller@users.sourceforge.net>
To: Jon Harrop <jon@jdh30.plus.com>
Cc: caml-list <caml-list@inria.fr>
Subject: Re: [Caml-list] Confused
Date: 16 Sep 2004 00:52:26 +1000	[thread overview]
Message-ID: <1095259945.27775.1034.camel@pelican.wigram> (raw)
In-Reply-To: <200409151428.54124.jon@jdh30.plus.com>

On Wed, 2004-09-15 at 23:28, Jon Harrop wrote:
> How come this works:
> 
> # let rec build = function 0 -> [] | n -> 1e-6 :: build (n-1);;
> val build : int -> float list = <fun>
> # let test = 1. :: build 1000;;
> val test : float list = ...
> 
> But this does not:
> 
> # let rec build = function 0 -> [] | n -> 1e-6 :: build (n-1) in
>   let test = 1. :: build 1000;;
> Syntax error
> 
> Am I being stupid?

The top level let is unrelated to the expression let/in.
It just happens to use the same keyword. I'll change the 
keyword to demonstrate:

toplet x = y;;
let x = y in z;;

The first form is a toplet statement, the second is an entirely
unrelated expression statement. Note that toplet explicitly
has side-effects -- it enriches the global environment with
the symbol x. The expression statement has side-effects 
if y and z do OR if you are using the command line 'ocaml'
program (it prints the type and value).

Now rewriting your example:


let rec build = function 0 -> [] | n -> 1e-6 :: build (n-1) in
  toplet test = 1. :: build 1000;;

you can see you've used a 'toplet' in an inner location
where an expression is expected: let/in is an expression,
toplet isn't.

Basically this syntax is a 'hack' used by language
designers, overloading related syntactic forms to avoid
introducing new keywords and to make the language 
'more intuitive' - which usually backfires on newbies
and even experts at times. 

Such impurity is annoying, however a fully 'orthogonal'
syntax may well be worse. For example seeing:

int_match x with | 1 -> ..
float_match x wth | 1.2 -> ...
variant_match x with | True -> 

you can probably agree some 'pattern matching' in the compiler
itself to discriminate these cases (and allow just plain 'match')
is probably justified.

-- 
John Skaller, mailto:skaller@users.sf.net
voice: 061-2-9660-0850, 
snail: PO BOX 401 Glebe NSW 2037 Australia
Checkout the Felix programming language http://felix.sf.net



-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


  parent reply	other threads:[~2004-09-15 14:52 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-09-14 17:47 [Caml-list] strange behaviour of ocamldoc Eugene Ossintsev
2004-09-15 13:28 ` [Caml-list] Confused Jon Harrop
2004-09-15 13:46   ` Michael
2004-09-15 13:51   ` Radu Grigore
2004-09-15 14:01   ` Brian Hurt
2004-09-15 14:13   ` Jon Harrop
     [not found]     ` <7f8e92aa04091507233d074f31@mail.gmail.com>
2004-09-15 14:23       ` Radu Grigore
2004-09-15 14:50         ` Virgile Prevosto
2004-09-15 14:57           ` Radu Grigore
2004-09-15 14:52   ` skaller [this message]
2004-09-15 18:42     ` William Lovas

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=1095259945.27775.1034.camel@pelican.wigram \
    --to=skaller@users.sourceforge.net \
    --cc=caml-list@inria.fr \
    --cc=jon@jdh30.plus.com \
    /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).