codesnippets:bindingandpatternmatching
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| codesnippets:bindingandpatternmatching [2021/04/14 11:06] – [Tuples] f2b216 | codesnippets:bindingandpatternmatching [2025/10/08 00:48] (current) – external edit 127.0.0.1 | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| - | ====== Binding ====== | + | ====== Binding |
| - | ~~DISCUSSION~~ | + | |
| A binding binds a name or even several names with a function definition. | A binding binds a name or even several names with a function definition. | ||
| Line 133: | Line 132: | ||
| * but with binding names | * but with binding names | ||
| * example | * example | ||
| - | * | ||
| * code lines:< | * code lines:< | ||
| data MyData = MyVariantA Integer Char Double | MyVariantB Int | MyVariantC | data MyData = MyVariantA Integer Char Double | MyVariantB Int | MyVariantC | ||
| Line 145: | Line 143: | ||
| print b | print b | ||
| print zet | print zet | ||
| - | print n | ||
| data MyData = MyVariantA Integer Char Double | MyVariantB Int | MyVariantC | data MyData = MyVariantA Integer Char Double | MyVariantB Int | MyVariantC | ||
| - | deriving Show | ||
| MyVariantA first b zet = MyVariantA 12 ' | MyVariantA first b zet = MyVariantA 12 ' | ||
| Line 154: | Line 150: | ||
| MyVariantB n = MyVariantB 123 | MyVariantB n = MyVariantB 123 | ||
| - | MyVariantC = MyVariantC | + | MyVariantC = MyVariantC |
| </ | </ | ||
| * with compiler warning, which we ignore for pedagogical reasons | * with compiler warning, which we ignore for pedagogical reasons | ||
| Line 163: | Line 159: | ||
| 123 | 123 | ||
| </ | </ | ||
| - | + | * NOTE: I may look like: It does' | |
| - | ==== Example 2 ==== | + | |
| - | + | ||
| - | <code Haskell> | + | |
| - | Person name number = Person " | + | |
| - | </ | + | |
| - | + | ||
| - | ...works | + | |
| - | + | ||
| - | <code Haskell> | + | |
| - | module Main where | + | |
| - | + | ||
| - | main :: IO () | + | |
| - | main = | + | |
| - | do | + | |
| - | print name | + | |
| - | print number | + | |
| - | + | ||
| - | data Person = Person { sName :: String, iNumber :: Integer } | + | |
| - | + | ||
| - | Person name number = Person " | + | |
| - | </ | + | |
| + | ===== ✎ ===== | ||
| + | ~~DISCUSSION~~ | ||
codesnippets/bindingandpatternmatching.1618391180.txt.gz · Last modified: (external edit)
