caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] ref
@ 2003-02-08 18:41 altavillasalvatore
  2003-02-09  0:06 ` Alessandro Baretta
  0 siblings, 1 reply; 3+ messages in thread
From: altavillasalvatore @ 2003-02-08 18:41 UTC (permalink / raw)
  To: caml-list

Hi all,
my problem is this:


let r = 
let a= ("b" , "c") in 
let f = ref "" in
let g = ref "" in
f:= fst a;
g:= snd a;
!f,!g;;


 val r : string * string = "b", "c"

I would want to call "a" one single time but....


let r = 
let a= ("b" , "c") in 
let f = ref "" in
let g = ref "" in
f,g := a;
!f, !g ;;

 Characters 68-71:
This expression has type string ref * string ref but is here used with type
  (string * string) ref

Regards.



-------------------
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


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [Caml-list] ref
  2003-02-08 18:41 [Caml-list] ref altavillasalvatore
@ 2003-02-09  0:06 ` Alessandro Baretta
  2003-02-09  0:17   ` William Lovas
  0 siblings, 1 reply; 3+ messages in thread
From: Alessandro Baretta @ 2003-02-09  0:06 UTC (permalink / raw)
  To: altavillasalvatore; +Cc: caml-list



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.

BTW, are you sure you need references?
Alex

-------------------
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


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [Caml-list] ref
  2003-02-09  0:06 ` Alessandro Baretta
@ 2003-02-09  0:17   ` William Lovas
  0 siblings, 0 replies; 3+ messages in thread
From: William Lovas @ 2003-02-09  0:17 UTC (permalink / raw)
  To: caml-list; +Cc: altavillasalvatore

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


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2003-02-09  0:17 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-02-08 18:41 [Caml-list] ref altavillasalvatore
2003-02-09  0:06 ` Alessandro Baretta
2003-02-09  0:17   ` William Lovas

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).