However, in many circumstances we don't wish to define a function every time we need to do this, but so far we have only shown how to do pattern matching in function definitions. Haskell's case expression provides a way to solve this problem. Indeed, the meaning of pattern matching in function definitions is specified in the Report in terms of case expressions, which are considered more primitive. The pattern-matching rules for case expressions are the same as we have given for function definitions, so there is really nothing new to learn here, other than to note the convenience that case expressions offer. There is one other kind of pattern allowed in Haskell.
Lazy patterns are useful in contexts where infinite data structures are being defined recursively.
For example, infinite lists are an excellent vehicle for writing simulation programs, and in this context the infinite lists are often called streams . Consider the simple case of simulating the interactions between a server process server and a client process client , where client sends a sequence of requests to server , and server replies to each request with some kind of response . This situation is shown pictorially in Figure 2, just as we did with the Fibonacci example. These recursive equations are a direct lexical transliteration of the diagram. Although workable, this solution does not read as well as that given earlier.