HPM Education - Haskell

Searchβ¦

Introduction

Types in Haskell

Defining Functions / Working with Functions

List Comprehensions

Higher-order Functions

Cutom Types

Interactive Programming

Functors, Applicatives and Monads

The Infix Operator

This is a good time to introduce the **infix operator** that helps us make code a bit more readable. Normally, we apply a function by writing

`<FUNCTION> <ARGUMENT1> <ARGUMENT2>`

, but we could also write it using the infix operator as`<ARGUMENT1> `<FUNCTION>` <ARGUMENT2>`

. This way, we make the code more readable β for example, in the case of`res = mod sum 2`

, we can write:1

res = sum `mod` 2 -- using the infix operator ``

Copied!

Which then reads as "**functions that take in two arguments**. For functions with more than two arguments, we would need to add parentheses to explicitly create expressions (which return another function β currying):

`res`

is equal to `sum modulo 2`

". Note that the infix operator can be used this way for 1

ghci> multiply x y z = x * y * z

2

β

3

ghci> (1 `multiply` 2) 3

4

6

Copied!

Copy link