13 Nov 03:22
Re: Pattern Matching
Brandon S. Allbery KF8NH <allbery <at> ece.cmu.edu>
2009-11-13 02:22:42 GMT
2009-11-13 02:22:42 GMT
On Nov 12, 2009, at 21:15 , Casey Hawthorne wrote: > Why in a pattern match like > > score (1 3) = 7 > > can I not have > > sizeMax = 3 > > score (1 sizeMax) = 7 Because it's a pattern, and when you introduce a symbol you are inviting the pattern match to bind what it matched to that name for use within the function. (Ordinary arguments are a trivial case of this.) Or, by example: > score (1 sizeMax) = (expression using sizeMax) The normal way to do what you want is guards: > score (1 x) | x == sizeMax = 7 -- you can pronounce the "|" as "such that" -- -- brandon s. allbery [solaris,freebsd,perl,pugs,haskell] allbery <at> kf8nh.com system administrator [openafs,heimdal,too many hats] allbery <at> ece.cmu.edu electrical and computer engineering, carnegie mellon university KF8NH
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe <at> haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
RSS Feed