Difference between revisions of "Cum definim operatorii binari ?"

From HaskellWiki
Jump to: navigation, search
 
(Deleting page that hasn't been edited for over 10 years)
Line 1: Line 1:
Ca pe orice functie binara, dar numele ei il veti scrie punind numele operatorului in paranteza rotunda.
 
 
Ex:
 
 
suma :: Int -> Int -> Int
 
suma a b = a + b
 
 
poate deveni
 
 
(+++) :: Int -> Int -> Int
 
(+++) a b = a + b
 
 
iar cu o declaratie [[infix]] precizati asociativitatea si nivelul de prioritate al operatorului.
 
 
 
Varianta: puteti folosi o functie binara obisnuita ca un operator infixat punandu-i numele intre `apostroafe inverse`.
 
 
Ex:
 
 
3 `suma` 4
 
 
va calcula tot : suma 3 4 adica 3 + 4 cf. def. de sus.
 

Revision as of 11:43, 6 February 2021