Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
* Some cosmetics problems with ocaml
@ 1996-11-18 15:23 Emmanuel Engel
  1996-11-19 16:35 ` Wolfgang Lux
  0 siblings, 1 reply; 2+ messages in thread
From: Emmanuel Engel @ 1996-11-18 15:23 UTC (permalink / raw)
  To: caml-list

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





^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Some cosmetics problems with ocaml
  1996-11-18 15:23 Some cosmetics problems with ocaml Emmanuel Engel
@ 1996-11-19 16:35 ` Wolfgang Lux
  0 siblings, 0 replies; 2+ messages in thread
From: Wolfgang Lux @ 1996-11-19 16:35 UTC (permalink / raw)
  To: Emmanuel Engel; +Cc: caml-list

Emanuel Engel wrote:
> I have some cosmetics problems with ocaml. 
> 
> [much stuff deleted]
>
> 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
> *******************************************************

You might use a functor in this case:

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

module FooSet = MakeFooSet(struct let eval_all = eval_all end)

Hope this helps,
Wolfgang

----
Wolfgang Lux
WZH Heidelberg, IBM Germany             Internet: lux@heidelbg.ibm.com
+49-6221-59-4546                        VNET:     LUX at HEIDELBG
+49-6221-59-3500 (fax)	                EARN:     LUX at DHDIBMIP





^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~1996-11-19 19:18 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1996-11-18 15:23 Some cosmetics problems with ocaml Emmanuel Engel
1996-11-19 16:35 ` Wolfgang Lux

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox