Re: Lazy Patterns (was: Curry module system and other proposals)

From: Michael Hanus <mh_at_informatik.uni-kiel.de>
Date: Wed, 01 Mar 2006 18:21:13 +0100

Wolfgang Lux wrote:
> Quite obviously, lazy patterns are most useful in declarations with
> only a single rule (because otherwise they are likely to give rise to
> unintended non-determinism).

Ok, but in these cases it is not a big task to replace
lazy patterns by let's. I agree that the code is a bit
more clumsy but on the other hand the condition under which
such a rule is applicable (i.e., the required patterns) is more
explicit.

> Another kind of examples where lazy patterns are useful are lazy stream
> processors. As an example, consider a stream of integers where after
> every
> third integer you want to a insert a sum of those numbers, but at the
> same time want to be as lazy as possible so that
> head (process (1:undefined)) = 1
> With lazy patterns you would do this as follows
>
> process (x : ~(y : ~(z : rest)) = x : y : z : (x+y+z) : process rest
>
> Without lazy patterns, you would have to use something like
>
> process (x : rest1) = x : y : z : (x+y+z) : process rest3
> where y : rest2 = rest1
> z : rest3 = rest2
>
> which, IMHO, is considerably less readable than the version using lazy
> patterns and also in danger of mixing up the rest? variables.

This is a nice example. The price to pay for this is a limitation
in the equational reading of function rules. An important fact
of Curry is that the different rules defining a function
have an equational reading, i.e., the order is not important
so that each rule can be interpreted as an equation under
which condition a function call can be replaced by another expression.
However, with lazy patterns you can define an operation

not ~True = False

and evaluate (not False) to False. Thus, the little tilde
(which is, by the way, the blank symbol in LaTeX...) has
a tremendous influence on the meaning of equations. Thus,
I think it is better to make this meaning more explicit
in the program code. My argument is less relevant for Haskell
since in Haskell many defining equations have no simple
equational reading due to the top-down strategy for
pattern matching. Therefore, I think it is better to
make this restriction in Curry.

Regards,

Michael

_______________________________________________
curry mailing list
curry_at_lists.RWTH-Aachen.DE
http://MailMan.RWTH-Aachen.DE/mailman/listinfo/curry
Received on Wed Mar 01 2006 - 18:26:29 CET

This archive was generated by hypermail 2.3.0 : Mon Nov 18 2019 - 07:15:05 CET