Skip to Content
Effective Haskell
book

Effective Haskell

by Rebecca Skinner
July 2023
Intermediate to advanced
670 pages
17h 13m
English
Pragmatic Bookshelf
Content preview from Effective Haskell

Writing Type Annotations for Functions

Functions in Haskell have types just like non-function values do. The types of Haskell functions are written using an arrow (->). Let’s look at an example of a function that takes an Int and adds 1 to it:

 addOne :: ​Int​ -> ​Int
 addOne n = n + 1

The type signature for this function says that it is going to accept an Int and will return an Int. From the type signature, you can also know that the variable n must be an Int. That’s because n is the first parameter to the function, and we’ve said in the function’s type that its parameter must be an Int.

It’s also possible to have function types that have parameters even when you’re not explicitly binding the parameter to a variable. For example, we can rewrite ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Grokking Functional Programming

Grokking Functional Programming

Michal Plachta
Grokking Algorithms

Grokking Algorithms

Aditya Bhargava
The Rust Programming Language, 2nd Edition

The Rust Programming Language, 2nd Edition

Steve Klabnik, Carol Nichols

Publisher Resources

ISBN: 9798888650400Errata Page