Simon wrote:

 | 1    x + 1 = f x
 | 2    (x + 1) = f 2
 |
 | [...]
 | 
 | (1) partially defines (+).  One could add more equations, thus:
 |      x + 1 = f x
 |      x + other = g x
 | 
 | (2) is a pattern binding that binds x.  It's quite like
 | 
 |      Just x = f 2
 | 
 |   except that the pattern is an n+k pattern

Umpf! I have always been in favor of n+k patterns (*), but this is really
ugly I think. I'd say: Junk them!

How about:

  2a. (x # 1) = g 2

??

Is this an error, or does it define (#)?

Simon also wrote:

 | Having said that, full laziness (which GHC does do) can change
 | asymptotic running time.  Consider
 | 
 |      f n = let g m = h n + m
 |              in sum (map g [1..n])
 | 
 | where h is linear in n.  The running time is n**2, but if you
 | lift out the invariant (h n) from the inside of g, you get back
 | to linear.

What happens to the space behavior of the program?

Regards,
Koen.

(*) I have even been in favor of (cs++xs) patterns. Consider:

  lex :: String -> [Lex]
  lex ('-':'-':' ':xs)                 = lex (dropWhile (/= '\n' xs))
  lex ('i':'m':'p':'o':'r':'t':' ':xs) = ...
  ...

Wouldn't it be nice to write it as:

  lex :: String -> [Lex]
  lex ("-- " ++ xs)      = lex (dropWhile (/= '\n' xs))
  lex ("import "  ++ xs) = ...
  ...

--
Koen Claessen,
[EMAIL PROTECTED],
http://www.cs.chalmers.se/~koen,
Chalmers University of Technology.


Reply via email to