User Tools

Site Tools


codesnippets:binding

Differences

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

Link to this comparison view

Both sides previous revisionPrevious revision
codesnippets:binding [2021/03/23 16:00] f2b216codesnippets:binding [2021/04/13 21:05] (current) – removed f2b216
Line 1: Line 1:
-====== Binding ====== 
-~~DISCUSSION~~ 
- 
-A binding binds a name or even several names with a function definition. 
- 
-In Haskell, a binding is defined by symbol "=" whereas 
-  - on the left hand side 
-     - the function name and its parameters  
-     - or a pattern is given,  
-  - and on the right had side the definition of the function. 
-===== 1) with function name and parameter ===== 
- 
-==== Example ==== 
- 
-<code Haskell> 
-half x = x / 2 
-</code> 
- 
-...works in... 
- 
-<code Haskell> 
-module Main where 
- 
-main :: IO () 
-main =  
-        do 
-                print $ half 5 
- 
-half x = x / 2 
-</code> 
- 
-===== 2) with pattern matching ===== 
- 
-==== Example 1 ==== 
- 
-<code Haskell> 
-(x1, x2, x3) = (42, "Hello", "World") 
-</code> 
- 
-...works in... 
- 
-<code Haskell> 
-module Main where 
- 
-main :: IO () 
-main =  
-        do 
-                print x1 
-                print x2 
-                print x3 
- 
-(x1, x2, x3) = (42, "Hello", "World") 
-</code> 
- 
-==== Example 2 ==== 
- 
-<code Haskell> 
-Person name number = Person "Lutz" 1243 
-</code> 
- 
-...works in... 
- 
-<code Haskell> 
-module Main where 
- 
-main :: IO () 
-main =  
-        do 
-                print name 
-                print number 
- 
-data Person = Person { sName :: String, iNumber :: Integer } 
- 
-Person name number = Person "Lutz" 1243 
-</code> 
- 
-==== Example 3 ==== 
- 
-<code Haskell> 
-(x1, Person x2 x3, x4) = ("...", Person "Lutz" 1243, '#') 
-</code> 
- 
-...works in... 
- 
-<code Haskell> 
-module Main where 
- 
-main :: IO () 
-main =  
-        do 
-                print x1 
-                print x2 
-                print x3 
-                print x4 
- 
-data Person = Person { sName :: String, iNumber :: Integer } 
- 
-(x1, Person x2 x3, x4) = ("...", Person "Lutz" 1243, '#') 
-</code> 
- 
- 
  
codesnippets/binding.1616511636.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