codesnippets:patternmatching
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| codesnippets:patternmatching [2021/04/14 12:44] – [Wildcard] f2b216 | codesnippets:patternmatching [2025/10/08 00:48] (current) – external edit 127.0.0.1 | ||
|---|---|---|---|
| Line 5: | Line 5: | ||
| * list comprehensions | * list comprehensions | ||
| * do notations | * do notations | ||
| + | * case constructs | ||
| Before we start with that, we provide more details about pattern matching, regarding: | Before we start with that, we provide more details about pattern matching, regarding: | ||
| Line 38: | Line 39: | ||
| getZipFromPerson (PersonNameZipAndEMail _ _ _ nZip _) = nZip | getZipFromPerson (PersonNameZipAndEMail _ _ _ nZip _) = nZip | ||
| </ | </ | ||
| - | * compiles... | + | * compiles, with warning: Pattern match(es) are non-exhaustive |
| * executes, with output:< | * executes, with output:< | ||
| " | " | ||
| Line 72: | Line 73: | ||
| main = | main = | ||
| do | do | ||
| - | print (length s) -- " | + | print (length s) |
| s :: String | s :: String | ||
| Line 78: | Line 79: | ||
| length :: [a] -> Integer | length :: [a] -> Integer | ||
| - | length [] = 0 | + | length [] = 0 -- "inner function perspective" |
| - | length (_:lrx) = 1 + (length lrx) | + | length (_:lrx) = 1 + (length lrx) -- "inner function perspective" |
| - | -- using the rest (lrx) for recursive call of length (again " | + | |
| + | </ | ||
| + | |||
| + | |||
| + | ===== ✎ ===== | ||
| + | ~~DISCUSSION~~ | ||
codesnippets/patternmatching.1618397097.txt.gz · Last modified: (external edit)
