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: Wolfgang Lux <lux@h...>
Subject: Re: Some cosmetics problems with ocaml
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