Previous week Up Next week

Hello

Here is the latest Caml Weekly News, for the week of August 29 to September 05, 2006.

  1. native values in objects from c
  2. 3.09.3 release candidate 1
  3. Continuations
  4. can ocamldep order .cmo files?
  5. offre d'emploi OCAML bioinformatique chef de projet/développeur
  6. Eliminating array bounds check

native values in objects from c

Archive: http://groups.google.com/group/fa.caml/browse_thread/thread/39f89356d68f6ace/d9476057f92c314d#d9476057f92c314d

Michael Wohlwend asked and Jacques Garrigue answered:
> with that code: 
> class x = object 
>  val name = "hoho" 
> end;; 

> let ho = new x in ... 

> how do I access the field name form C? 

> The docu says it should be the third field of the block, but that doesn't
> work for me (it has Tag 0, not 252 for strings ...) 


Well, since fields start at 0, the 3rd field is number 2. 
# Obj.size (Obj.repr ho);; 
- : int = 3 
# Obj.tag (Obj.field (Obj.repr ho) 2);;                     
- : int = 252 
		
Michael Wohlwend then asked and Jacques Garrigue answered:
> thanks for helping; actually my fault was to think the elements are linear
> ordered, even if the class is inherited (I want to get the first value of
> the base). The values are ordered reverse of definition, whereas the docu
> says: 
> "Instance variables are stored in the order in which they appear in the
> class definition" 

> In the end I want to hide public methods which give you access the the
> pointer to the c++ object and hiding an external method is easy. 

Aargh, you're right. The behaviour changed between 3.08 and 3.09. 
In 3.08, fields are still ordered in definition order, including 
inherited ones, but in 3.09, due to an optimization, inherited fields 
appear after newly defined ones. The trouble is that this being due 
to an optimization, this may change again, so it is not a good idea to 
depend on it. 
Note also that it is pretty easy to define another object, with the 
same type as the one you want to interface with C++, but with 
completely different fields. I.e., accessing object fields from the C 
side is always dangerous. 
A better approach it to add a method which returns the field with an 
abstract type, this way users cannot break the type system.
		

3.09.3 release candidate 1

Archive: http://groups.google.com/group/fa.caml/browse_thread/thread/0945e1328494273d/37c90ae0c61b12a4#37c90ae0c61b12a4

Damien Doligez announced:
We have a release candidate for 3.09.3.  It is available from the CVS 
repository < http://camlcvs.inria.fr/cvsserver-eng.html > under the 
tag "ocaml3093rc1". 

We would appreciate the help of any user who wants to test this 
version and report any problem encountered (as usual, through the 
BTS: < http://caml.inria.fr/mantis/main_page.php >). 

It will become a full release in one or two weeks unless some serious 
bug is reported in the meantime.
		
Olivier Andrieu then added:
Here's the Changelog by the way: 

,----[ Changes ] 
| Objective Caml 3.09.3: 
| ---------------------- 
| 
| Bug fixes: 
| - ocamldoc: -using modtype constraint to filter module elements displayed 
|     in doc PR#4016 
| - ocamldoc: error in merging of top dependencies of modules PR#4007 
| - ocamldoc: -dot-colors has no effect PR#3981 
| - ocamdloc: missing crossref in text from intro files PR#4066 
| - compilers: segfault with recursive modules PR#4008 
| - compilers: infinite loop when compiling objects PR#4018 
| - compilers: bad error message when signature mismatch PR#4001 
| - compilers: infinite loop with -rectypes PR#3999 
| - compilers: contravariance bug in private rows 
| - compilers: unsafe cast with polymorphic exception PR#4002 
| - native compiler: bad assembly code generated for AMD64 PR#4067 
| - native compiler: stack alignment problems on MacOSX/i386 PR#4036 
| - stdlib: crash in marshalling PR#4030 
| - stdlib: crash when closing a channel twice PR#4039 
| - stdlib: memory leak in Sys.readdir PR#4093 
| - C interface: better definition of CAMLreturn PR#4068 
| - otherlibs/unix: crash in gethostbyname PR#3043 
| - tools: subtle problem with unset in makefile PR#4048 
| 
| New features: 
| - ocamldoc: name resolution in cross-referencing {!name}: if name is not 
|     found, then it is searched in the parent module/class, and in the parent 
|     of the parent, and so on until it is found. 
| - ocamldoc: new option -short-functors to use a short form to display 
|     functors in html generator PR#4017 
| - ocamlprof: added "-version" option 
`----
		

Continuations

Archive: http://groups.google.com/group/fa.caml/browse_thread/thread/cabde087446087e3/37852870d9f92153#37852870d9f92153

Tom asked and Jacques Carette answered:
> Has anyone implemented continuations in pure, dirty OCaml yet? 
> (pure = no C, dirty = Obj.magic) 

It can be done in pure, clean Ocaml.  See 
http://caml.inria.fr/pub/ml-archives/caml-list/2006/07/530ba0e13ce88fab8ee0e981d65b70b1.en.html
as well as 
http://caml.inria.fr/pub/ml-archives/caml-list/2006/02/8fc9c1a56c497b9743515a5e3432d704.en.html
If you want delimited continuations, see 
http://caml.inria.fr/cgi-bin/hump.en.cgi?contrib=508
		

can ocamldep order .cmo files?

Archive: http://groups.google.com/group/fa.caml/browse_thread/thread/7bd6ac21b330fd27/a894391df56a788b#a894391df56a788b

Continuing a thread, Jean-Baptiste Rouquier answered Nathan Mishra Linger:
> I'm a new OCaml user and quite a fan so far (most of my functional 
> programming experience has been in Haskell up to this point). 
> I know that .cmo arguments to ocamlc must be in order of dependency. 
> I also know that ocamldep can detect such dependencies and spit them 
> out in a format that makefiles can include. 

> But can ocamldep spit out the dependency ordering of a list of .cmo 
> files in such a way that these can be input to ocamlc?  If not, it 
> seems like it would be a useful thing for ocamldep to be able to do 
> this.  Or do people have other solutions to this problem. 

For a tiny script (sed+tsort) that does only this, you might want to have a 
look at 
http://jb.rouquier.free.fr/programmation/ocamldep2moduleList.zip 	
		
Henry Bigelow also suggested:
also, look at ocamldsort from 
http://dimitri.mutu.net/ocaml.html 

this link is from another post.  i just downloaded it today though, and 
it works fine 
		

offre d'emploi OCAML bioinformatique chef de projet/développeur

Archive: http://groups.google.com/group/fa.caml/browse_thread/thread/80d6342632f9329c/4088c1ddefffe902#4088c1ddefffe902

Fabrice Moriaud announced:
Nous profitions de cette liste de diffusion pour toucher les programmeurs en 
caml/ocaml.  Nous sommes désolés d’avoir utilisé ce canal de diffusion pour 
tous ceux qui ne seraient pas du tout intéressés par ce genre d’offre 
d’emploi. 

Nous avons un code innovant de bioinformatique écrit en OCAML et nous 
cherchons à recruter dans les prochaines semaines une personne capable de 
reprendre un code existant, de l’optimiser et de développer de nouvelles 
fonctionnalités. Idéalement le candidat sera très à l’aise en OCAML et sera 
expérimenté dans notre domaine bioinformatique/modélisation moléculaire. 

Pour plus de précisions, le texte de l’annonce, en anglais est dans la suite 
de ce mail, 

N’hésitez pas à nous contacter pour tout renseignement ou candidature, 

Merci d’avance pour les candidatures qui proviendront de cette liste de 
diffusion, 

Cordialement, 

F. Moriaud 

THREE SOFTWARE DEVELOPERS in MOLECULAR MODELING 

MEDIT SA is a French start-up providing highly specialized software and 
services in Molecular Modeling and Cheminformatics. Our leading edge 
technology is based on fast 3D protein-ligand structure comparison. 

MEDIT SA is looking for 3 software developers and molecular modeling experts 
to develop current and new software components for structure-based drug 
design. 

The successful candidates will possess the following skills along with a 
passion for innovative environment: 

  - confirmed expertise in software development 

  - background in protein-ligand interactions and molecular modeling 

  - MS in science plus experience or PhD level 

Additional background in OpenGL or OCAML or MS-VisualStudio.Net would be a 
decisive advantage. 

MEDIT offers to qualified applicants a competitive package including Stock 
Options. The position is based in Palaiseau (closed to Paris) 

Motivated applicants should contact François Delfaud at: 

fdelfaud@medit.fr (cc fmoriaud@medit.fr) 

For further information: 

http://www.medit.fr/
		

Eliminating array bounds check

Archive: http://groups.google.com/group/fa.caml/browse_thread/thread/078940042cc3edd6/a7a409cf54eb694e#a7a409cf54eb694e

John Skaller said and Oleg answered:
> Typing is always an abbreviation (abstraction) and sometimes 
> stronger or weaker than desired: for example array bounds 
> checks at run time, because the type system doesn't cope 
> with array sizes as part of the type. 

Although that is true that making the type system track the size of a 
(dynamically allocated) array is too much of a hassle, array bounds 
checks at run-time can be entirely and safely avoided, in OCaml as it 
is. 
For example: 
 http://pobox.com/~oleg/ftp/ML/eliminating-array-bound-check-literally.ml 

shows how to implement the bsearch (the standard Dependent ML example 
from the famous Xi and Pfenning's PLDI98 paper) in the current 
OCaml. The above code has exactly the same number of checks as the DML 
code; there are no array bound checks -- and yet the code has the same 
static assurances of the absence of out-of-bounds array access 
errors. The code (given at the end of that file) even looks quite like 
the original DML code (quoted at the beginning of that file), only 
without any type annotations. 

A more interesting example is the textbook KMP string search, which 
uses mutable arrays, general recursion, and creative index expressions 
(with mutable arrays storing array indices). 

  http://pobox.com/~oleg/ftp/Computation/lightweight-dependent-typing.html 

(well, the referenced code is actually in Haskell, but it is easy to 
re-write it in OCaml; I can do that if called to). 

The above page points to the PLPV talk that contains formalization and 
the proof method (as well some proofs in Twelf). Briefly, we rely on 
the type system to propagate assurances made in a small `security 
kernel' through the rest of the code. The security kernel does have to 
be verified. Our examples show that the kernel is far simpler than the 
rest of the code: the KMP kernel, for example, is made of 
non-recursive functions performing additions and subtraction of 
integers. 
		
Alain Frisch suggested:
> For example: 
>  http://pobox.com/~oleg/ftp/ML/eliminating-array-bound-check-literally.ml 
>From your code: 

======================================= 
(* First, we, on off-chance, check if we can obtain type 
   eigen-variables via the module system. 
*) 
module GenT : sig type t val v : t end = 
  struct type t = int let v = 1 end 
;; 
let module M1 = GenT in 
let module M2 = GenT in 
M1.v = M2.v 
;; 

(* Alas, the latter succeeds and reports no type error. What did we 
   expect: OCaml functors are applicative. 
   Fortunately, OCaml supports higher-rank types. 
*) 
======================================= 

What about making GenT a functor and passing it unnamed structures as 
arguments? (Ok, you must then trust the client not to apply GenT with 
named structures.) 

module GenT(X:sig end) : sig type t val v : t end = 
  struct type t = int let v = 1 end 
;; 
let module M1 = GenT(struct end) in 
let module M2 = GenT(struct end) in 
M1.v = M2.v 
;; 

You could then simplify the TrustedKernel so as not to use polymorphic 
record fields (and also to use a direct style instead of a continuation 
style for brand). 		
		
Alain Frisch then added:
> What about making GenT a functor and passing it unnamed structures as 
> arguments? (Ok, you must then trust the client not to apply GenT with 
> named structures.) 

Actually, GenT should be a functor anyway, since the abstract types in 
the resulting structure must encode invariants which depends on the 
(length of the) array. Unfortunaly, you cannot make a polymorphic 
functor such as: 
  module GenT(A : sig val a : 'a array end) ... 

As a work-around, you can take only the length of the array as an argument: 

  module TrustedKernel(L: sig val len: int end) : sig 
      type 'a barray 
      type bindex 
      val unbi : bindex -> int 

      type bindexL 
      type bindexH 
      ... 
  end = struct 
      let brand a = 
         assert(Array.length a = L.len); 
         (a,0,L.len - 1) 
  end 

On the one hand, this adds one run-time check, but on the other hand it 
makes the abstract index types depend only on the length (so the trusted 
kernel could be used in algorithms which work with several arrays of the 
same size simultaneously).
		

Using folding to read the cwn in vim 6+

Here is a quick trick to help you read this CWN if you are viewing it using vim (version 6 or greater).

:set foldmethod=expr
:set foldexpr=getline(v:lnum)=~'^=\\{78}$'?'&lt;1':1
zM

If you know of a better way, please let me know.


Old cwn

If you happen to miss a CWN, you can send me a message and I'll mail it to you, or go take a look at the archive or the RSS feed of the archives.

If you also wish to receive it every week by mail, you may subscribe online.


Alan Schmitt