Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Caml-list] Sample code doesn't work
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Alain Frisch <frisch@c...>
Subject: Re: [Caml-list] Sample code doesn't work
On Mon, 16 Jul 2001, Rolf Wester wrote:

> let rec make_account wert0 = 
>   let wert = wert0 in
>   let add wert_ =
>     make_account (wert+.wert_)
>   in   
>   let sub wert_ =
>     make_account (wert-.wert_)
>   in 
>   let get () = 
>     wert 
>   in
>   (add, sub, get);;
> 
> When trying to evaluate this I get the error message:
> 
> This expression has type
>   (float -> 'a * 'b * 'c) * (float -> 'a * 'b * 'c) * (unit -> float)
> but is here used with type 'a * 'b * 'c
> 
> How can I make this work?

You need recursive types to be able to unify these two type
expressions. It is often the case when you want, as in this
example, simulate the object paradigm.

Just add the -rectypes switch to the toplevel/compiler command line.


-- 
  Alain Frisch

-------------------
Bug reports: http://caml.inria.fr/bin/caml-bugs  FAQ: http://caml.inria.fr/FAQ/
To unsubscribe, mail caml-list-request@inria.fr  Archives: http://caml.inria.fr