User Tools

Site Tools


codesnippets:patternmatching

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
codesnippets:patternmatching [2022/10/05 14:21] – external edit codesnippets:patternmatching [2025/10/08 00:48] (current) – external edit 127.0.0.1
Line 1: Line 1:
-~~DISCUSSION~~ 
 ====== Pattern matching, again ====== ====== Pattern matching, again ======
  
Line 6: 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 73: Line 73:
 main =  main = 
     do     do
-        print (length s)                            -- "caller perspective" for first parameter of function length+        print (length s)             -- "caller perspective" for first parameter of function length
  
 s :: String s :: String
Line 79: Line 79:
  
 length :: [a] -> Integer length :: [a] -> Integer
-length [] = 0                                       -- "inner function perspective" - selected when list is empty +length [] = 0                        -- "inner function perspective" - selected when list is empty 
-length (_:lrx) = 1 + (length lrx)                   -- "inner function perspective" - selected when at least one element +length (_:lrx) = 1 + (length lrx)    -- "inner function perspective" - selected when at least one element 
-                                                      -- using the rest (lrx) for recursive call of length (again "caller perspective")</code>+                                     -- using the rest (lrx) for recursive call of length (again "caller perspective") 
 +</code> 
 + 
 + 
 +===== ✎ ===== 
 +~~DISCUSSION~~
codesnippets/patternmatching.1664972507.txt.gz · Last modified: (external edit)

Except where otherwise noted, content on this wiki is licensed under the following license: CC0 1.0 Universal
CC0 1.0 Universal Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki