© 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 the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.