Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Caml-list] ref
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: William Lovas <wlovas@s...>
Subject: Re: [Caml-list] ref
On Sun, Feb 09, 2003 at 01:06:18AM +0100, Alessandro Baretta wrote:
> 
> 
> altavillasalvatore@libero.it wrote:
> 
> >f,g := a;
> >!f, !g ;;
> 
> You are asking too much of the assignment operator. You must 
> remember that Ocaml does not support operator overloading, 
> so you cannot define a
> val (:=) : 'a ref -> 'a -> unit
> 
> and a
> val (:=) : ('a * 'b) ref -> ('a * 'b) -> unit
> 
> This would require a form of "generic overloading" of (:=) 
> over all tuple types. This is really a little too much, I think.

I think you mean for your second example to be:

    val (:=) : ('a ref * 'b ref) -> ('a * 'b) -> unit


What you originally wrote,

    val (:=) : ('a * 'b) ref -> ('a * 'b) -> unit ,

is just a more specific instance of

    val (:=) : 'a ref -> 'a -> unit .


The original poster could accomplish his goal with something like:

    let (a1,a2) = a in
    f := a1;
    g := a2;
    !f, !g;;

but ...

> BTW, are you sure you need references?

... i agree that this is probably the right question to be asking :)

cheers,
William
-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners