Version française
Home     About     Download     Resources     Contact us    
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 fool.ml > 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 foo.ml > a;mv a foo.mli". But again I have some 
problems. 

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 
  
**** foo.ml *******

let f 1 = 1 
 
******************

the resulting a file will be

******** foo.mli ********
File "foo.ml", 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 
definitions.


**** foo.ml ******************

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:

************* foo.ml ********************
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);
      v;
  | _  ->
      ()

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


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