Re: Proposal: Lazy matching for local patterns

From: German Vidal <>
Date: Tue, 23 Oct 2001 17:19:32 +0200 (CEST)

hi all,

> the semantics of purely functional programs in Curry is mostly similar
> to that of Haskell (except for the handling of overlapping rules).
> However, there is one major difference, which results in valid Haskell
> programs to fail under Curry: The lifting algorithm given in appendix
> D.8 of the report is too strict wrt local patterns. E.g. consider the
> definition
> foo xy = length [x,y]
> where (x,y) = xy
> In Haskell the expression "foo undefined" evaluates to 2, while in
> Curry this expression fails. Another example is
> bar n xy
> | n == 0 = success
> | otherwise = x =:= y
> where (x,y) = xy
> for which the expression "bar 0 undefined" is going to fail even though
> the argument xy is not used at all.

Yes, I agree with your proposal. When programming in Curry,
I usually rewrite the above function to something like

  bar n xy
    | n == 0 = success
    | otherwise = bar' xy

  bar' (x,y) = x =:= y

in order to avoid the problem you mentioned. And this situation
occurs very often in practice...

Just one thing:

> The evaluation annotation for the f_i serves the purpose to avoid a
> possible instantiation of the result of e' by any of the functions f_i,
> which is IMHO not very useful and -- due to the lazy evaluation of the
> applications -- in fact unpredictable.

I'm not sure about this change. In principle, one expects
that variables get instantiated by local declarations
(indeed, this is how it actually works in PAKCS).

What could be the problems? Could you provide a concrete

Best wishes,

 German Vidal
 DSIC - UPV, Camino de Vera s/n, E-46022 Valencia, Spain

curry mailing list
Received on Di Okt 23 2001 - 17:18:58 CEST

This archive was generated by hypermail 2.3.0 : Mo Dez 04 2023 - 07:15:06 CET