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 [2024/06/02 22:11] – [Context: function definition] f2b216codesnippets: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 72: 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 78: 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~~ ~~DISCUSSION~~
codesnippets/patternmatching.1717359083.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