caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* output_value
@ 1995-10-20  3:48 Makofka, Doug (HT-MS)
  1995-10-20 13:53 ` output_value Christian Boos
  1995-10-20 19:18 ` output_value Pierre Weis
  0 siblings, 2 replies; 3+ messages in thread
From: Makofka, Doug (HT-MS) @ 1995-10-20  3:48 UTC (permalink / raw)
  To: Caml-list




could someone comment on the difference between:
    do_list (output_value chan) ProductionLst
and
    output_value chan ProductionLst

 I guess what I'm looking for is an output_value statement that will allow 
me to say:
  let rec IterateProductionList = fun chan ->
    (match (input_value chan:ProductionValue) with
       t -> SomeCrazyFunctionOnProductionValue t;
         IterateProductionList chan
       | [] -> ())
;;

     thanks in advance,
     doug makofka
     dmakofka@gic.gi.com

  




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

* output_value
  1995-10-20  3:48 output_value Makofka, Doug (HT-MS)
@ 1995-10-20 13:53 ` Christian Boos
  1995-10-20 19:18 ` output_value Pierre Weis
  1 sibling, 0 replies; 3+ messages in thread
From: Christian Boos @ 1995-10-20 13:53 UTC (permalink / raw)
  To: Makofka, Doug (HT-MS); +Cc: Caml-list



Doug Makofka writes:
 > could someone comment on the difference between:
 >     do_list (output_value chan) ProductionLst
 > and
 >     output_value chan ProductionLst

The second form is often better, since all you need to do for
retrieval and use is something like :

  do_list SomeCrazyFunctionOnProductionValue
	(input_value chan : ProductionValue list) 

However, if your 'ProductionLst' is constructed piece by piece, and if
it may grows very large, then you need perhaps the first form, but in
a slightly different way that the one you suggested. The 'do_list ...'
you wrote only outputs ProductionValues, without any structure along
them.
So, you'd better write :

  type 'a option = Some of 'a | None;;
  
  do_list (fun p -> output_value chan (Some p)) ProductionLst;
  (* - maybe multiple times - *)

  (* and, when you're done :  *)

  output_value chan None

Latter, you can retrieve your production values one by one:

let do_production_value_chan f chan =
  let rec do_one () =
     match (input_value chan:ProductionValue) with
     | Some p -> f p; do_one ()
     | None -> ()
   in
   do_one () 
;;

Hope it helps!

---------------------------------
Christian Boos





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

* Re: output_value
  1995-10-20  3:48 output_value Makofka, Doug (HT-MS)
  1995-10-20 13:53 ` output_value Christian Boos
@ 1995-10-20 19:18 ` Pierre Weis
  1 sibling, 0 replies; 3+ messages in thread
From: Pierre Weis @ 1995-10-20 19:18 UTC (permalink / raw)
  To: Makofka Doug; +Cc: caml-list


> could someone comment on the difference between:
>     do_list (output_value chan) ProductionLst
> and
>     output_value chan ProductionLst

If you output the entire list at once you preserve sharing between
values (and their subparts) that are in the list. This could make a
big difference. Still, when you input the list its very easy to
iterate on it.

Otherwise, if there is no sharing involved, and if you want to spare the space
occupied by the list cells, output the elements. Then you can input
them one at a time until end_of_file is reached.
(try 
  while true do f (input_value chan) done
 with Eof -> ())

Pierre Weis
----------------------------------------------------------------------------
WWW Home Page: http://pauillac.inria.fr/~weis
Projet Cristal
INRIA, BP 105, F-78153 Le Chesnay Cedex (France)
E-mail: Pierre.Weis@inria.fr
Telephone: +33 1 39 63 55 98
Fax: +33 1 39 63 53 30
----------------------------------------------------------------------------




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

end of thread, other threads:[~1995-10-20 19:19 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1995-10-20  3:48 output_value Makofka, Doug (HT-MS)
1995-10-20 13:53 ` output_value Christian Boos
1995-10-20 19:18 ` output_value Pierre Weis

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