Graded Type Theory provides a mechanism to track and reason about resource usage in type systems. In this paper, we develop GraD, a novel version of such a graded dependent type system that includes functions, tensor products, additive sums, and a unit type. Since standard operational semantics is resource-agnostic, we develop a heap-based operational semantics and prove a soundness theorem that shows correct accounting of resource usage. Several useful properties, including the standard type soundness theorem, non-interference of irrelevant resources in computation and single pointer property for linear resources, can be derived from this theorem. We hope that our work will provide a base for integrating linearity, irrelevance and dependent types in practical programming languages like Haskell.
Modern Haskell supports zero-cost coercions, a mechanism where types that share the same run-time representation may be freely converted between. To make sure such conversions are safe and desirable, this feature relies on a mechanism of roles to prohibit invalid coercions. In this work, we show how to incorporate roles into dependent types systems and prove, using the Coq proof assistant, that the resulting system is sound. We have designed this work as a foundation for the addition of dependent types to the Glasgow Haskell Compiler, but we also expect that it will be of use to designers of other dependently-typed languages who might want to adopt Haskell's safe coercions feature. A newtype in Haskell 1 is a user-defined algebraic datatype with exactly one constructor; that constructor takes exactly one argument. Here is an example:
newtype HTML = MkHTML StringThis declaration creates a generative abstraction; the HTML type is new in the sense that it is not equal to any existing type. We call the argument type (String) the representation type. Because a newtype is isomorphic to its representation type, the Haskell compiler uses the same in-memory format for values of these types. Thus, creating a value of a newtype (i.e., calling MkHTML) is free at runtime, as is unpacking it (i.e., using a pattern-match).However, the Haskell type checker treats the newtype and its representation type as wholly distinct, meaning programmers cannot accidentally confuse HTML objects with String objects. We thus call newtypes a zero-cost abstraction: a convenient compile-time distinction with no cost 1 In this paper, we use łHaskellž to refer to the language implemented by the Glasgow Haskell Compiler (GHC), version 8.6.
scite is a Brooklyn-based organization that helps researchers better discover and understand research articles through Smart Citations–citations that display the context of the citation and describe whether the article provides supporting or contrasting evidence. scite is used by students and researchers from around the world and is funded in part by the National Science Foundation and the National Institute on Drug Abuse of the National Institutes of Health.