In my last article, we went over getting Haskell setup on your machine. If you haven’t read that article you can read it here.

“Learning Haskell” is a series of articles I’m writing around my journey learning Haskell Hopefully I can also teach you a few things about Haskell too.

Arithmetic

At the end of my previous article on getting set up with Haskell, we started to play around with the REPL by performing some arithmetic. This is pretty self explanatory for people coming from other programming languages, so I’ll keep things brief. If you load up your REPL with the ghci or stack ghci commands you can begin adding, subtracting, multiplying, and dividing integers and floats.

Image for post

arithmetic in the ghci REPL

We can also use parenthesis to ensure precedence.

Image for post

arithmetic with brackets

What happens if we try and add an integer and a string together?

1 + “nespite” in Haskell

We get an error! That’s because “nespite” is not an integer or a float and so Haskell doesn’t know how to add 1 and “nespite” together, you can only add integers and floats together.

#programming #functional-programming #series #tutorial #haskell

Learning Haskell: Getting Started
1.10 GEEK