Re: Help with a little function called "choose"

From: Michael Hanus <mh_at_informatik.uni-kiel.de>
Date: Tue, 13 Jun 2006 09:12:42 +0200

Matthew Naylor wrote:
> I have two variables, one of which may never be instantiated, and I
> would like to know which becomes instantiated first. This function
> might look something like
>
> choose :: () -> () -> Int
> choose () _ = 0
> choose _ () = 1
>
> And if my understanding is correct, a "choose eval choice" annotation
> is what I want. But neither PAKCS or MCC support committed choice.
>
> Can "choose" be easily implemented as an external function in either
> PAKCS or MCC?

It depends on the exact meaning of "which becomes instantiated first".

If you just want to check which of the two variables is
instantiated at the time of the evaluation, Sergio already
showed you a solution in PAKCS. However, such a use heavily
depends on the order of evaluation and should be avoided in
application programs.

If you want to wait/suspend until one of the two variables
becomes instantiated, you need some sort of committed choice.
This is not supported in PAKCS and MCC since it has major
implications on the run-time system (e.g., you need fair threads
in order to implement the committed choice in a fair manner).
However, a good replacement of committed choice are ports
which are supported in PAKCS. A port is a constraint between
a multiset of messages (the client side) and a list of messages
(the server side) so that the multiset and the list always contain
the same messages. Thus, a port supports a fair merge of messages
so that ports provide in most cases an appropriate alternative
to committed choice (this depends on the application and I don't
know what you have in mind).

More details about the port concept can be found in the paper

http://www.informatik.uni-kiel.de/~mh/publications/papers/PPDP99.html

and the PAKCS library

http://www.informatik.uni-kiel.de/~pakcs/lib/CDOC/Ports.html

Best regards,

Michael

_______________________________________________
curry mailing list
curry_at_lists.RWTH-Aachen.DE
http://MailMan.RWTH-Aachen.DE/mailman/listinfo/curry
Received on Tue Jun 13 2006 - 09:16:03 CEST

This archive was generated by hypermail 2.3.0 : Fri Sep 20 2019 - 07:15:06 CEST