Talk:Haskell/Pattern matching
From Wikibooks, the open-content textbooks collection
Contents |
[edit] 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)
[edit] 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!
- No because the Type Declarations are a later chapter. You can't recall something from later in the book.
well, you can "pattern match" against constants like 0 or 'a'... shouldn't they be mentioned? --Uchchwhash 16:36, 17 February 2007 (UTC)
[edit] 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:
[edit] 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.
[edit] List comprehensions
Assumes understanding of Maybe & Just.
[edit] 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)
[edit] 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?
Note
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:
Note
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:
a, b, c = 1, 2, 3
-
- or a bit elaborated
def func():
return 1, 2, 3
a, b, c = func()
--The Kid (talk) 04:53, 1 September 2008 (UTC)
[edit] 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.