O'Reilly logo

Get Programming with Haskell by Will Kurt

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Unit 2. Introducing types

Nearly every programming language supports some idea of types. Types are important because they define the kinds of computation allowed on certain data. Take, for example, the text "hello" and the number 6. Say you want to do something like add them together:

"hello" + 6

Even someone with no prior programming experience would find this question interesting, because it’s not clear what to do. The two most obvious answers are to

  • Throw an error
  • Combine these values in the most reasonable way: "hello6"

To arrive at either option, you need a way to keep track of the type of your data, as well as the type of data your computation is expecting. Typically, we call the value of "hello" a String, and the value of 6 an

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required