Re: Some cosmetics problems with ocaml

Wolfgang Lux (lux@heidelbg.ibm.com)
Tue, 19 Nov 96 17:35:38 +0100

Message-Id: <9611191635.AA60112@idse.heidelbg.ibm.com>
To: Emmanuel Engel <Emmanuel.Engel@lri.fr>
Subject: Re: Some cosmetics problems with ocaml
In-Reply-To: (Your message of Mon, 18 Nov 96 16:23:50 N.)
<32907F85.15BC@lri.fr>
Date: Tue, 19 Nov 96 17:35:38 +0100
From: Wolfgang Lux <lux@heidelbg.ibm.com>

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