© Stefania Loredana Nita and Marius Mihailescu 2019
Stefania Loredana Nita and Marius MihailescuHaskell Quick Syntax Referencehttps://doi.org/10.1007/978-1-4842-4507-1_7

7. Functions

Stefania Loredana Nita1  and Marius Mihailescu1
(1)
Bucharest, Romania
 

In the previous chapters, you mainly worked with predefined functions from different libraries in Haskell. Now, it’s time to write your own functions. In this chapter, you will learn about pattern matching, guards, clauses, higher-order functions, and lambda expressions used in functions.

Let’s start with a simple function that adds two numbers.
add :: Integer -> Integer -> Integer
add x y =  x + y
main = do
   putStrLn "Adding two numbers:"
   print(add 3 7)
On the first line is the function declaration, ...

Get Haskell Quick Syntax Reference: A Pocket Guide to the Language, APIs, and Library now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.