Hi,
On Apr 15, 2009, at 3:18 PM, Гилмуллин Рушан wrote:
> I have one question about Curry.
>
> I have two patterns
>
> parse s | s =:= <first pattern> = ...
> parse s | s =:= <second pattern> = ...
>
> I want, the second match work only if the first match failed.
In Curry there is a subtle difference between "constraint guards" and
"boolean guards": the latter support "fall-through" the former do not.
In general, if you write multiple rules for a function then they are
executed independently. Whether or not the first matches has no impact
on whether the second is executed.
You can rewrite your program to use boolean guards like this
parse s | s == <first pattern> = ...
| s == <second pattern> = ...
because boolean guards support fall-through semantics. If you need
=:=, e.g., to bind free variables, then you are stuck. There is no
easy way to detect a failing computation (i.e. one without results) in
Curry.
If you really need it, there is a way: the module AllSolutions
provides operations to enumerate all results of an expression. However
these operations are in the IO monad and can not be used in guards
directly.
Cheers,
Sebastian
_______________________________________________
curry mailing list
curry_at_lists.RWTH-Aachen.DE
http://MailMan.RWTH-Aachen.DE/mailman/listinfo/curry
Received on Do Apr 16 2009 - 09:11:13 CEST