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

Guarded Equations

`MultiWayIfs`

, they represent a sequence of expressions that evaluate to either True or False (conditions) which are individually called guards and are used to decide the flow of the program. The syntax is very similar to `MultiWayIf`

syntax and allows us to get rid of the `if`

altogether:trackScore :: Float -> Float -> String

trackScore time avgTime

| time < avgTime = "Great! Your time is " ++ show (avgTime - time) ++ "

seconds below average!"

| time > avgTime = "Your time is " ++ show (time - avgTime) ++ "

seconds above average."

| otherwise = "Your time is on par with the average time!"

Note that in the above implementation of **guarded equations**, we have **moved the equation sign** in the line **replaced the ifs arrow**

`trackScore time avgTime`

, and we have `(->)`

with it.Last modified 1yr ago

Copy link