Re: Help with a little function called "choose"

From: Sergio Antoy <antoy_at_cs.pdx.edu>
Date: Mon, 12 Jun 2006 12:57:58 -0700

Hi Matthew,

The following PAKCS fragment tells you which variable is
instantiated, if any. If both variables are instantiated,
however, it does NOT tell you which was instantiated FIRST.
I hope it helps nevertheless.

Now, a word of wisdom. I think that the need to know whether a
variable is instantiated should be very rare indeed. Perhaps,
your solution to the problem you are facing is bad, if such
solution relies on knowing whether a variable is instantiated.

Good luck and have fun with with pakcs,
Sergio

import Unsafe

choose :: a -> a -> String
choose a b = helper (isVar a) (isVar b) where
   helper True True = "Neither var is instantiated"
   helper True False = "Only the second var is instantiated"
   helper False True = "Only the first var is instantiated"
   helper False False = "Both vars are instantiated"

test00 = choose a b where a,b free
test10 = choose "a" b where b free
test01 = choose a "b" where a free
test11 = choose "a" "b"

> Date: Mon, 12 Jun 2006 20:02:37 +0100
> From: Matthew Naylor <mattfn_at_gmail.com>
> Subject: Help with a little function called "choose"
> Sender: curry-bounces_at_lists.RWTH-Aachen.DE
> To: curry_at_lists.RWTH-Aachen.DE
> Content-disposition: inline
> DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com;
> h=received:message-id:date:from:to:subject:mime-version:content-type:content-transfer-encoding:content-disposition;
> b=qU0RySrb1V9xm23BfoD9PuyP+rDorpf4vRBaMA1xU14nVlzSHSIPGjEn1RIvxPPNNbsXlLW70pNr3GncBBhoqPxf+iH+Uo7A8avoq7MzBDed0X9qORA5ed3Y5MTEwhEA5hnwKTDBqmR3yzZxZJXyqB7SYmEWP3kO3WqJfni0C2w=
> X-Spam-Checker-Version: SpamAssassin 3.0.4 (2005-06-05) on
> sword.rz.RWTH-Aachen.DE
> X-Spam-Level:
> X-Spam-Status: No, score=0.1 required=5.5 tests=BAYES_50,RCVD_BY_IP
> autolearn=ham version=3.0.4
> X-Virus-Scanned: by amavisd-new
>
> Dear Curry enthusiasts,
>
> 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?
>
> I have written one useful external function for PAKCS (a generic
> mapAccum), but defining "choose" is a little beyond my expertise!
>
> Hints much appreciated!
>
> Thanks,
>
> Matt.
>
> _______________________________________________
> curry mailing list
> curry_at_lists.RWTH-Aachen.DE
> http://MailMan.RWTH-Aachen.DE/mailman/listinfo/curry
>

_______________________________________________
curry mailing list
curry_at_lists.RWTH-Aachen.DE
http://MailMan.RWTH-Aachen.DE/mailman/listinfo/curry
Received on Tue Jun 13 2006 - 08:50:38 CEST

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