Version française
Home     About     Download     Resources     Contact us    
Browse thread
Type annotations
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Jacques Garrigue <garrigue@k...>
Subject: Re: Ref syntax
From: Ohad Rodeh <orodeh@cs.huji.ac.il>

>   I have a modest syntax request as we are approaching
> the release of OCaml-3.01. Currently, if x is a
> reference, one must use the assignment operator (:=) to
> update it. Can array assignment (<-) be used also? 

Sorry, but this does not work: this may be confused with record assignment.

       type t = {mutable x : int ref};;
       let r = {x = ref 1};;
       r.x <- ref 2;;
       r.x := 3;;

So here is also my wishlist for Santa Xavier.

* addition of let mutable ... in
       let mutable x = 0 in
       for i = 1 to do x <- x + i done;
       x
  The idea is to have references which are certified not to be
  returned or passed to functions. Easy.
  Makes lots of thing clearer, but it might be a good idea to allow
  only the let ... in form, since toplevel let mutable is rather
  opposed to functional programming.

* addition of let open ... in
       module P2d = struct type t = {x:int;y:int} end
       module P3d = struct type t = {x:int;y:int;z:int} end
       let f2d p1 p2 =
         let open P2d in
         {x = p1.x + p2.x; y = p1.y + p2.y}
  Extremely easy.

* allow #labels in programs
  avoids subtle makefiles when you have both files with and without
  labels, also avoid to check the mode before compiling a file.

* have a notation to abbreviate the OCAMLLIB directory in include
  paths. One could write
       ocamlc -c -I +labltk -I +lablGL gears.ml
  rather than
       ocamlc -c -I `ocamlc -where`/labltk -I `ocamlc -where`/lablgGL gears.ml

I would be already satisfied with only one of these...

Cheers,

Jacques
---------------------------------------------------------------------------
Jacques Garrigue      Kyoto University     garrigue at kurims.kyoto-u.ac.jp
		<A HREF=http://wwwfun.kurims.kyoto-u.ac.jp/~garrigue/>JG</A>