Math operators
Try it yourself →Four basic operations, integer division, and remainder.
Syntax
+ - * div mod /
Description
Integer division is with div, and remainder with mod. / is only used with floating-point (Double) numbers (7.0/2.0).
Example
main = do print (7 + 3) print (div 7 2) print (mod 7 2) print (7.0 / 2.0)
Expected output
10 3 1 3.5
When to use?
Calculations, even/odd check (mod x 2 or even).
Common mistakes
- ⚠️ Do not use / with Int; perform integer operations with div/mod.