Function definition
Try it yourself →Defining your own function.
Syntax
name :: Type -> Type\nname param = expression
Description
Functions are written as 'name parameter = expression'; a type signature (::) is placed above. Calls are without parentheses, and arguments are separated by spaces.
Example
addUp :: Int -> Int -> Int addUp a b = a + b main = print (addUp 8 9)
Expected output
17
When to use?
Preventing code repetition, breaking the program into parts.
Common mistakes
- ⚠️ Calls are without parentheses: addUp 8 9 (not addUp(8,9)).