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:res = sum `mod` 2 -- using the infix operator ``

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 ghci> multiply x y z = x * y * z

β

ghci> (1 `multiply` 2) 3

6

Copy link