Is there any way to simulate the combinator fail using Kiama's rule combinator?
TIA,
--Hossein
--------------------------------------------------------------------------------------------------------------
Seyed H. HAERI (Hossein)
Research Assistant
Institute for Software Systems (STS)
Technical University of Hamburg (TUHH)
Hamburg, Germany
ACCU - Professionalism in programming - http://www.accu.org/
--------------------------------------------------------------------------------------------------------------
> Is there any way to simulate the combinator fail using Kiama's rule combinator?
rule (f) is constrained by applicability of the partial function f, so you can get fail if f is a partial function that is never applicable. I don't think it's possible to build one of those with the function shorthand in Scala, but you could create one specifically using the PartialFunction class (just make the isDefinedAt method always return false).
A far easier method to get fail is to use one of the strategy* variants of rule. E.g.,
def strategyf (f : Term => Option[Term]) : Strategy
This function exposes the success/fail result to your control using an Option return type for the argument function. strategyf (f) fails exactly when f returns None, and succeeds with t when f returns Some (t). Therefore you can get fail by writing
strategyf (_ => None)
Tony
>> Is there any way to simulate the combinator fail using Kiama's rule combinator?
>
> rule (f) is constrained by applicability of the partial function f, so you can get fail if f is a partial function that is never applicable.
That's exactly what I thought but...
> you could create one specifically using the PartialFunction class (just make the isDefinedAt method always return false).
... I didn't make thus far. Nice job. :)
> A far easier method to get fail is to use one of the strategy* variants of rule. E.g.,
<snip>
Sure. As a riddle, this only occurred to me and I though it would be
interesting to share... :)
Thanks,