Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
Some cosmetics problems with ocaml
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Emmanuel Engel <Emmanuel.Engel@l...>
Subject: Some cosmetics problems with ocaml
I have some cosmetics problems with ocaml. 

First it is not possible to simply create mli files with the command 
"ocamlc -c -i > foo.mli". There is at least three reasons.

First the compiler complain that we must  compile interface file first. 
I need a compilation option to solve this problem. Something saying 
"generate .mli file forme infered type" will be OK.

I can try "ocamlc -c -i > a;mv a foo.mli". But again I have some 

The first problem is that I have no solution to suppress warnings from  
the compiler output. So if i try to compile the following file with 
**** *******

let f 1 = 1 

the resulting a file will be

******** foo.mli ********
File "", line 1, characters 6-10:
Warning: this pattern-matching is not exhaustive
val f : int -> int

This file does not compile.

The second problem is with mutualy recursives type 

**** ******************

type foo = N
         | C of int * froz ref

and  froz = V of foo
	  | T of (unit -> foo)  

the resulting foo.mli will be :

********* foo.mli *************
type foo = N | C of int * froz ref
type froz = V of foo | T of (unit -> foo)

This file does not compile.

That's all for interfaces. Let's talk about modules. 

Sometimes I want to define sets or map or somethings else for 
a specifics data structure. I used to put the module set inside 
the module that define the data structure. I want to extend the 
function that I have defined for my data structure to sets. I 
find usefull to keep the same name for the function's extension 
but this is quite difficult: I can't refer to a function with is 
fully qualified name inside the module definition. 

Let's take an example. I'd like to write:

************* ********************
type foo = N
         | C of int * froz ref

and  froz = V of foo
	  | T of (unit -> foo)  

let rec eval_all = function
    C(_,{contents=V x}) -> 
      eval_all x;
  | C(_,({contents=T f} as t)) ->
      let v= f () in
      t.contents <- (V v);
  | _  ->

module FooSet=
    type t = int list 
    let rec eval_all = function
      |	[]     ->
      |	hd::tl ->
	  (Foo.eval_all hd);
          (Foo.FooSet.eval_all tl)

The problem is the last function eval_all. The values Foo.eval_all
and Foo.FooSet.eval_all are undefined. I must write something like

let eval_all = 
  let rec f = function
     []   ->
    |hd::tl ->
        (eval_all hd);
        (f tl) in f

I find it less practical. 


- Emmanuel Engel