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

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: boos@g...
Subject: output_value


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