- Contemporary messages sorted: [ by date ] [ by thread ] [ by subject ] [ by author ] [ by messages with attachments ]

From: Michael Hanus <mh_at_informatik.uni-kiel.de>

Date: Wed, 12 Oct 2005 17:19:30 +0200

Sebastian Fischer wrote:

*> > The second one serves the same purpose as the prelude function
*

*> > until, but for constrains instead of booleans.
*

*> >
*

*> > cuntil f x = case allValuesOf (f x) of
*

*> > [] -> x
*

*> > (r:_) -> cuntil f r
*

*>
*

*> this would be a nice extension, although I think the name is a bit
*

*> misleading: "until" stops when the given boolean predicate holds, and
*

*> "cuntil" continues while the condition holds. Maybe we should call it
*

*> cwhile then?
*

It seems to me that the operation is even more general since

it applies the transformation as long as the result is a defined value.

Thus, "whileDefined" could be a better name. For the reasons

already explained by Bernd, I'd prefer to put it into a

module like AllSolutions

(http://www.informatik.uni-kiel.de/~pakcs/lib/CDOC/AllSolutions.html)

as an I/O action. Using the operation getFirstSolution already

defined there, one can implement whileDefined as follows:

whileDefined :: (a -> a) -> a -> IO a

whileDefined f x =

getFirstSolution (=:=(f x)) >>= maybe (return x) (whileDefined f)

However, the analogon to "until" would be an operation "untilValid"

which could be defined as follows:

untilValid :: (a -> Success) -> (a -> a) -> a -> IO a

untilValid c f x =

getFirstSolution (=:=(c x)) >>=

maybe (untilValid c f (f x)) (const (return x))

Of course, if such operations are often used, it seems reasonable

to provide them also in the prelude. At least the function

"getAllValues" is a good candidate.

Best regards,

Michael

_______________________________________________

curry mailing list

curry_at_lists.RWTH-Aachen.DE

http://MailMan.RWTH-Aachen.DE/mailman/listinfo/curry

Received on Mi Okt 12 2005 - 17:50:04 CEST

Date: Wed, 12 Oct 2005 17:19:30 +0200

Sebastian Fischer wrote:

It seems to me that the operation is even more general since

it applies the transformation as long as the result is a defined value.

Thus, "whileDefined" could be a better name. For the reasons

already explained by Bernd, I'd prefer to put it into a

module like AllSolutions

(http://www.informatik.uni-kiel.de/~pakcs/lib/CDOC/AllSolutions.html)

as an I/O action. Using the operation getFirstSolution already

defined there, one can implement whileDefined as follows:

whileDefined :: (a -> a) -> a -> IO a

whileDefined f x =

getFirstSolution (=:=(f x)) >>= maybe (return x) (whileDefined f)

However, the analogon to "until" would be an operation "untilValid"

which could be defined as follows:

untilValid :: (a -> Success) -> (a -> a) -> a -> IO a

untilValid c f x =

getFirstSolution (=:=(c x)) >>=

maybe (untilValid c f (f x)) (const (return x))

Of course, if such operations are often used, it seems reasonable

to provide them also in the prelude. At least the function

"getAllValues" is a good candidate.

Best regards,

Michael

_______________________________________________

curry mailing list

curry_at_lists.RWTH-Aachen.DE

http://MailMan.RWTH-Aachen.DE/mailman/listinfo/curry

Received on Mi Okt 12 2005 - 17:50:04 CEST

*
This archive was generated by hypermail 2.3.0
: Do Jun 13 2024 - 07:15:07 CEST
*