Type systems

Clojure is homoiconic, functional, lazy, and list-based. But, it's also a typed language—dynamically typed in this case (https://en.wikipedia.org/wiki/Type_system#DYNAMIC). In computer science, type systems are tools that are mainly used to reduce bugs and improve the correctness of programs. What follows is not an exhaustive discourse on type systems. We only explore their rationale and variations. It's important to know that type systems are just tools that programming languages can employ under a certain set of conditions. There are different categories of type systems: duck typing, dependent types, gradual typing, and so on. In computation, type systems present an approach to data representation and transformation. Haskell, for example, encourages a very strict way of data representation and data transformation. Its type system is very closely derived from category theory (https://en.wikipedia.org/wiki/Category_theory), which is a mathematical formalism. Essentially, category theory rigorously tries to take some state and transform it to another state. These are attempts at having a provable system. The focus on types of data and their transformations gives us more clarity on when and why we should use these tools. There's a lot of value in having a system that we can prove is always correct for a given set of concurrent, distributed inputs. These properties are important in many domains: military, finance, global communications, and so on.

To apply these concepts in the real world, let's think in terms of mathematics and consider how acoustic waves get transformed into digital representations. How is video captured, and what algorithms can we run over top of the data to flip it, or get a negative of an image. So, what is an image and how would you represent it digitally, in order to perform some of these interesting transformations? These data representation and transformation questions are what Type Systems are addressing. Type systems are closely related to and informed by type theory (also used in mathematics and logic), which formally studies the different forms of type systems. Type systems try to assure correctness by applying types to program elements (functions, variables, and so on). It may be useful to think of types as a contract between program elements to behave in a certain way. The contracted behavior can be checked at compile time (statically) or runtime (dynamically). Compile time or static checking generally enforces contracted behavior for a certain set of inputs when a program is being generated (this is called the compilation process). This is meant to ensure the correctness of a program before it's run. Runtime or dynamic checking is used while the program is running. Its purpose is to ensure that the program makes decisions based on the types or subtypes it encounters (runtime polymorphism). You can also combine static and dynamic type checking.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.133.156.251