caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* Puzzle
@ 2005-08-26 19:21 David Thomas
  2005-08-26 20:27 ` [Caml-list] Puzzle Christophe Raffalli
  2005-08-27 11:53 ` Berke Durak
  0 siblings, 2 replies; 3+ messages in thread
From: David Thomas @ 2005-08-26 19:21 UTC (permalink / raw)
  To: caml-list

I have three lists that I would like to have sorted
through user interaction.  I can, of course, say
"List.sort ask list" for each list.  What if, however,
rather than sorting each list in turn, I wanted the
questions to be interleaved, either randomly or in a
prespecified sequence?  Is it possible to do this
without reimplementing sort?  I easily could, but it
seems more fun without...

__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 


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

* Re: [Caml-list] Puzzle
  2005-08-26 19:21 Puzzle David Thomas
@ 2005-08-26 20:27 ` Christophe Raffalli
  2005-08-27 11:53 ` Berke Durak
  1 sibling, 0 replies; 3+ messages in thread
From: Christophe Raffalli @ 2005-08-26 20:27 UTC (permalink / raw)
  To: David Thomas, caml-list

David Thomas a écrit :
> I have three lists that I would like to have sorted
> through user interaction.  I can, of course, say
> "List.sort ask list" for each list.  What if, however,
> rather than sorting each list in turn, I wanted the
> questions to be interleaved, either randomly or in a
> prespecified sequence?  Is it possible to do this
> without reimplementing sort?  I easily could, but it
> seems more fun without...
> 

This should work (I did not test ...), But the input output may
not work, One should have a separate thread to interact with the user
and the sorting thread sending request to this thread ... but you may 
assume all this is done by the ask function.

let tsort l =
   let r = ref [] in
   let g l = r := List.sort ask l in
   let th = Thread.create g l in
   th, r

let result =
   let th1, r1 = tsort l1 in
   let th2, r2 = tsort l2 in
   let th3, r3 = tsort l3 in
   Thread.join th1;
   Thread.join th2;
   Thread.join th3;
   !r1, !r2, !r3



> __________________________________________________
> Do You Yahoo!?
> Tired of spam?  Yahoo! Mail has the best spam protection around 
> http://mail.yahoo.com 
> 
> _______________________________________________
> Caml-list mailing list. Subscription management:
> http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
> Archives: http://caml.inria.fr
> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
> Bug reports: http://caml.inria.fr/bin/caml-bugs


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

* Re: [Caml-list] Puzzle
  2005-08-26 19:21 Puzzle David Thomas
  2005-08-26 20:27 ` [Caml-list] Puzzle Christophe Raffalli
@ 2005-08-27 11:53 ` Berke Durak
  1 sibling, 0 replies; 3+ messages in thread
From: Berke Durak @ 2005-08-27 11:53 UTC (permalink / raw)
  To: David Thomas; +Cc: caml-list

On Fri, Aug 26, 2005 at 12:21:17PM -0700, David Thomas wrote:
> I have three lists that I would like to have sorted
> through user interaction.  I can, of course, say
> "List.sort ask list" for each list.  What if, however,
> rather than sorting each list in turn, I wanted the
> questions to be interleaved, either randomly or in a
> prespecified sequence?  Is it possible to do this
> without reimplementing sort?  I easily could, but it
> seems more fun without...

Of course, you could first ask all the questions to the user and store the
answers, then use List.sort.
-- 
Berke Durak


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

end of thread, other threads:[~2005-08-27 11:53 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-08-26 19:21 Puzzle David Thomas
2005-08-26 20:27 ` [Caml-list] Puzzle Christophe Raffalli
2005-08-27 11:53 ` Berke Durak

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