* [Caml-list] Sample code doesn't work
@ 2001-07-16 15:43 Rolf Wester
2001-07-16 15:51 ` Alain Frisch
0 siblings, 1 reply; 2+ messages in thread
From: Rolf Wester @ 2001-07-16 15:43 UTC (permalink / raw)
To: caml-list
Hi,
I have a problem with the following simple example:
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?
Rolf Wester
-------------------------------------
Rolf Wester
wester@ilt.fhg.de
-------------------
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
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [Caml-list] Sample code doesn't work
2001-07-16 15:43 [Caml-list] Sample code doesn't work Rolf Wester
@ 2001-07-16 15:51 ` Alain Frisch
0 siblings, 0 replies; 2+ messages in thread
From: Alain Frisch @ 2001-07-16 15:51 UTC (permalink / raw)
To: Rolf Wester; +Cc: caml-list
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
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2001-07-16 15:51 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-07-16 15:43 [Caml-list] Sample code doesn't work Rolf Wester
2001-07-16 15:51 ` Alain Frisch
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox