English version
Accueil     À propos     Téléchargement     Ressources     Contactez-nous    

Ce site est rarement mis à jour. Pour les informations les plus récentes, rendez-vous sur le nouveau site OCaml à l'adresse ocaml.org.

Browse thread
object constructor syntax compiler weirdness
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2005-11-21 (08:09)
From: Mike Lin <mikelin@m...>
Subject: object constructor syntax compiler weirdness
Hello,

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.


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

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