Chapter 2. Data Types
This chapter offers an overview of the Q# type system: the data types available in Q# and the corresponding literals.
The chapter starts with a review of the Q# type system and the principles it follows. Then I cover primitive data types—classical, which have equivalents in classical programming languages, and quantum, which are specific to quantum programs. After that I introduce data structures—arrays, tuples, and user-defined types. Note that in this chapter I’ll focus on the data types themselves, and I’ll cover the operators and expressions used to work with values of each type in Chapter 3.
Q# supports elements of functional programming, which means it treats operations and functions similarly to other data types. However, this topic deserves special attention, so I’ll discuss Q# operations and functions separately in Chapter 5.
The Q# Type System
Let’s start with a quick review of Q#’s type system: the set of rules and principles that assign types to various elements of a program, such as variables, expressions, or callables. The following principles will give you a good idea of how Q# types work.
- Q# is a type-safe language.
-
Q# doesn’t allow operations or type conversions that violate the rules of the type system.
- Q# is statically typed.
-
All type checking is done during compile time, rather than during the program execution. The types are associated with variables, similar to C#, rather than with values, as in Python: once the Q# compiler determines ...
Get Q# Pocket Guide now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.