Cum definim operatorii binari ?

From HaskellWiki
Revision as of 15:17, 6 February 2021 by Gwern (talk | contribs) (Reverted edits by Tomjaguarpaw (talk) to last revision by Ha$kell)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

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.