caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Jacques Garrigue <garrigue@math.nagoya-u.ac.jp>
To: mikelin@mit.edu
Cc: caml-list@yquem.inria.fr
Subject: Re: [Caml-list] object constructor syntax compiler weirdness
Date: Mon, 21 Nov 2005 09:48:01 +0100 (CET)	[thread overview]
Message-ID: <20051121.094801.126142370.garrigue@math.nagoya-u.ac.jp> (raw)
In-Reply-To: <2a1a1a0c0511210009n24691c9eiad3046e4e0bce779@mail.gmail.com>

From: Mike Lin <mikelin@mit.edu>

> The following are by no means common or advisable syntax, but I was
> curious if there is a rationale behind why certain things are syntax
> errors or not. I'm using 3.08.4 -- apologies if this was fixed or
> modified in 3.09.

I have no rationale, but at least I can explain.

> class circle radius =
>   let pi = 3.14159 in
>   object
>    method area = pi *. radius *.radius
>   end
> 
> >> fine
> 
> class circle2 radius =
>   let pi = 3.14159 in
>     print_endline "Creating a circle";
>     object
>      method area = pi *. radius *.radius
>     end
> 
> >> syntax error

The things you are able to write in the prefix of a class constructor
are more limited than in normal functions.
In the above case, I would say that it would be a bit confusing.
You can of course write it
  let () = print_endline "Creating a circle" in object ... end

Another thing you cannot write is

  class ... = let module M = ... in object ... end.

In that cases there are difficulties related to mixing module scope
with class definitions (which have there own notion of scope), making
it rather difficult to introduce it.

> Most curiously:
> 
> class circle3 radius =
>   let pi = 3.14159 in
>     (object
>       method area = pi *. radius *.radius
>      end)
> 
> >> fine
> 
> class circle4 radius =
>   let pi = 3.14159 in
>     begin
>      object
>       method area = pi *. radius *.radius
>      end
>     end
> 
> >> syntax error

Parentheses in class definitions are useless, so there is no reason to
add a begin .. end construct. I suppose that the first syntax is only
allowed as a degenerated case of
   class c = (object ... end : ct)

Jacques Garrigue


  reply	other threads:[~2005-11-21  8:48 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-11-21  8:09 Mike Lin
2005-11-21  8:48 ` Jacques Garrigue [this message]
2005-11-21 10:14   ` [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=20051121.094801.126142370.garrigue@math.nagoya-u.ac.jp \
    --to=garrigue@math.nagoya-u.ac.jp \
    --cc=caml-list@yquem.inria.fr \
    --cc=mikelin@mit.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;
as well as URLs for NNTP newsgroup(s).