Talk:Haskell/Pattern matching

Could this chapter be made a bit more verbose?
I appreciated how the Beginner track provided quite a bit of explanation and elaboration on concepts. I feel that I've stepped off into the deep end for a moment here. If someone who knows could go through this chapter and just expand and draw connections and things I think it would be improved.--Jberryman (talk) 01:58, 4 March 2008 (UTC)

What is pattern matching?
Algebraic datatypes and the 'data' keyword appear without prior explanation.


 * Thanks for the tip! I've linked algebraic datatypes to the relevant chapter. Do you think this is enough? -- Kowey 06:22, 31 August 2006 (UTC)


 * No because the Type Declarations are a later chapter. You can't recall something from later in the book.
 * This is not the case any more, Type Declarations are now previous. Great!

well, you can "pattern match" against constants like 0 or 'a'... shouldn't they be mentioned? --Uchchwhash 16:36, 17 February 2007 (UTC)
 * Just wrote a section on literal values to cover that --Duplode (talk) 01:08, 3 May 2010 (UTC)

lot of forward references
Case expressions are on the next page, Lambda is known to be part of the Greek alphabet - seriously, most of the "Where you can use it" section are heavily dependant on later chapters! See also:

Let expressions / Where clauses
"Just x": it's assumed that the reader knows lookup returns Just something, and we are "discarding the Just", whatever that means.

List comprehensions
Assumes understanding of Maybe & Just.

Comments on above
Yep! Thanks for pointing that out. This makes me rather convinced that doing things in the public is the best way to go. People find your errors for you for free. My attention is too divided right now to work on this. I'm partly waiting for Hal to loosen his copyright on YAHT so that the wikibooks admins feel more comfortable with the issues (personally, I think it's just an implicit dual license - Hal keeps his stricter copyright, but accords us the GFDL). When this is done, we can start remixing in earnest and really shaking things down. In the meantime, if you feel that you have a bit of time on your hands, be bold and try rearranging it yourself! (it doesn't hurt to put a word on Talk:Haskell though. The worst that can happen is that somebody will not like it and change it back :-). Thanks again, -- Kowey 06:10, 27 October 2006 (UTC)

Just a note about double meanings
I'm learning haskell from this (excellent) tutorial after trying to learn it before with others.. (besides monads) I keep getting hung up on pattern matching because of the use of the same term in Perl, et al. It would clear up a lot of confusion if you explained right away that these are not the same concepts and maybe explain how they differ (or are similar). Thx --207.14.29.3 21:19, 19 July 2007 (UTC)

I agree. I was understanding things fairly easily up until this chapter. Coming from a Python/C/Java background, I was expecting pattern matching to be regular expressions. --anglozaxxon 11:05, 19 October 2007 (UTC)


 * Thanks for the comments. Is the following helpful?

{{body note|1=

Pattern matching on what?
Some languages like Perl and Python use pattern matching in a very specific way, that is to match regular expressions against strings. The pattern matching we are referring to in this chapter is quite different. In fact, you're probably best of forgetting what you know about pattern matching for now. Here, pattern matching is used in the same way as in others ML-like languages : to deconstruct values according to their type specification.}}
 * Anyway, it's what I've included in the text for now. -- Kowey 14:45, 19 October 2007 (UTC)


 * -1. I suggest this to be changed, pattern matching as in regular expression and pattern matching as in value deconstruction is quite a different terms, just cut the explanation short into something like this:

{{body note|1=

A short note about the term "Pattern Matching"
In some languages, like Perl and Python, the term "Pattern Matching" is used to mean matching regular expression patterns against strings. The pattern matching we are referring to in this chapter is not about regular expression. Here, pattern matching means deconstructing values according to their type specification. It is similar to tuple assignment in Python, but is much, much more powerful.}}


 * reason is because Haskell's pattern matching is more akin to multiple assignment (tuple assignment) in Python than regex matching.


 * PS: tuple assignment in Python is like this:


 * or a bit elaborated

--The Kid (talk) 04:53, 1 September 2008 (UTC)

A comment about "to deconstruct values according to their type specification"
Doesn't pattern matching extend beyond values to functions as well? In that sense, pattern matching is not just about values or their type specifications, but also ad hoc matching of functions that produce those values and type specifications.

Records? Just? Maybe? List Comprehensions? Lambda?
There are lots of mentions of topics that haven't been covered yet. All of the above are mentioned in this module as examples of pattern matching, but without knowing what they are, the examples are of no use. It would probably be better to have pattern matching using only the syntax we have so far covered. Pattern matching for other topics can be shown when those topics are taught in other modules.
 * I second that. At least records should be handled in [Haskell/Type_declarations]. List comprehensions could be introduced together with lists. --SealedSun (talk) 12:19, 3 April 2009 (UTC)