Re: Proposal: Lazy matching for local patterns

From: German Vidal <gvidal_at_dsic.upv.es>
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
example?

Best wishes,
German

---------------------------------------------------------
 German Vidal
 DSIC - UPV, Camino de Vera s/n, E-46022 Valencia, Spain
 gvidal_at_dsic.upv.es
 http://www.dsic.upv.es/~gvidal
--------------------------------------------------------


_______________________________________________
curry mailing list
curry_at_lists.RWTH-Aachen.DE
http://MailMan.RWTH-Aachen.DE/mailman/listinfo/curry
Received on Di Okt 23 2001 - 17:18:58 CEST

This archive was generated by hypermail 2.3.0 : Do Jun 20 2024 - 07:15:06 CEST