Summary Formal Specification of Lexically Scoped Type Variables arxiv.org
12,063 words - PDF document - View PDF document
One Line
The text discusses the formal specification of lexically scoped type variables in Haskell, including their limitations and the introduction of visible type application.
Slides
Slide Presentation (12 slides)
Key Points
- The paper discusses the need for language support for lexically scoped type variables in Haskell.
- The shortcomings of the existing ScopedTypeVariables extension are highlighted.
- Visible type application in patterns is proposed as a natural extension to GHC's existing visible type applications.
- The paper addresses the issue of binding existentially quantified type variables in patterns.
- The limitations and shortcomings of pattern signatures are discussed.
- The formal specification of the proposed language extensions is provided in the paper.
- The paper presents a formal specification of lexically scoped type variables in Haskell.
- The addition of support for Generalized Algebraic Data Types (GADTs) and pattern synonyms is discussed.
Summaries
16 word summary
Formal specification of lexically scoped type variables in Haskell, addressing limitations and introducing visible type application.
73 word summary
This paper presents a formal specification of lexically scoped type variables in Haskell, proposing visible type application in patterns to address the limitations of the ScopedTypeVariables extension. It also introduces visible type application for both universal and existential variables. The authors extend the type system to handle GADTs and pattern synonyms, introducing existential type variables and equality constraints. The paper also introduces closed and open pattern signatures for annotating patterns with type signatures.
156 word summary
This paper presents a formal specification of lexically scoped type variables in Haskell. It proposes visible type application in patterns as a solution to the limitations of the existing ScopedTypeVariables extension. The paper also addresses the issue of binding existentially quantified type variables in patterns, introducing visible type application for both universal and existential variables. The formal specification of the proposed language extensions is provided, including grammar and typing rules. The authors extend the existing type system to handle Generalized Algebraic Data Types (GADTs) and pattern synonyms, introducing existential type variables and equality constraints. The extended type system allows polytypes to include constraints, with the environment extended to track the scope of type variables and constraints. The paper also introduces closed and open pattern signatures for annotating patterns with type signatures, providing new typing rules for each. In conclusion, the paper extends the existing type system with lexically scoped type variables, supporting GADTs and pattern synonyms.
374 word summary
This paper presents a formal specification of lexically scoped type variables in Haskell. It proposes visible type application in patterns as a solution to the limitations of the existing ScopedTypeVariables extension, allowing users to explicitly specify type arguments of data constructors in patterns. The paper also addresses the issue of binding existentially quantified type variables in patterns, introducing visible type application for both universal and existential variables. It argues that visible type application is a more flexible and intuitive alternative to pattern signatures for binding type variables in patterns.
The formal specification of the proposed language extensions is provided, including grammar and typing rules. The paper emphasizes the benefits of visible type application in patterns and the need for further exploration and implementation of these language extensions. Additionally, the paper discusses the addition of support for Generalized Algebraic Data Types (GADTs) and pattern synonyms. The authors extend the existing type system to handle GADTs by introducing existential type variables and equality constraints. They also introduce pattern synonyms, allowing users to define new patterns and bind type variables within them.
The extended type system allows polytypes to include constraints, with the environment extended to track the scope of type variables and constraints. Data constructor types are modified to support GADTs, with constructors able to include constraints. Pattern matching with GADTs requires bringing type variables into scope and adding learned type equalities to the environment. The authors provide updated typing rules for pattern matching to prevent skolem escape and track internal variables brought into scope.
The paper introduces closed pattern signatures for annotating patterns with type signatures, providing a new typing rule for closed pattern signatures and explaining how the subtyping relationship is checked. It explores the interpretation of assumed equalities in the context as let-bindings and extends the existing approach to include such forms. Finally, support for open pattern signatures is introduced, allowing type variables to be brought into scope.
In conclusion, the paper extends the existing type system with lexically scoped type variables to support GADTs and pattern synonyms. It provides a detailed explanation of the modifications made to the type system and illustrates their approach with examples. The authors argue that their design is flexible and extensible while addressing potential issues and limitations.
636 word summary
This paper presents a formal specification of lexically scoped type variables in Haskell. It discusses the limitations of the existing ScopedTypeVariables extension and proposes visible type application in patterns as a more concise and elegant solution. This feature allows users to explicitly specify the type arguments of data constructors in patterns.
The paper also addresses the issue of binding existentially quantified type variables in patterns. It introduces visible type application in patterns for both universal and existential variables, allowing users to bring type variables into scope and disambiguate data constructors involving existential types.
Furthermore, the paper highlights the limitations of pattern signatures for binding type variables in patterns. It argues that visible type application in patterns is a more flexible and intuitive alternative.
The formal specification of the proposed language extensions is provided, including the grammar and typing rules for the language without scoped type variables or type equalities. The paper concludes by emphasizing the benefits of visible type application in patterns and the need for further exploration and implementation of these language extensions.
In addition to lexically scoped type variables, the paper discusses the addition of support for Generalized Algebraic Data Types (GADTs) and pattern synonyms. The authors extend the existing type system to handle GADTs by introducing existential type variables and equality constraints. They also introduce pattern synonyms, which allow users to define new patterns and bind type variables within them.
The extended type system allows polytypes to include constraints, which can be empty, an equality between monotypes, or a conjunction of constraints. The environment is extended to track the scope of type variables and the constraints that are in scope. Constraints are proved by an entailment relation.
Data constructor types are modified to support GADTs, with the return type of a constructor no longer limited to a quantified type variable. Constructors can also include constraints, and type equalities must be satisfied when a data constructor is used in an expression.
Pattern matching with GADTs requires bringing type variables into scope and adding the learned type equalities to the environment. The paper updates the typing rules for pattern matching to prevent skolem escape and track internal variables brought into scope.
The authors note that their type system is comparable in expressiveness to existing specifications. They highlight the importance of handling nested patterns correctly in the presence of GADTs and provide an example to illustrate this point.
One technical contribution of the paper is a simplified and more uniform rule for pattern matching with GADTs. The authors argue that their approach treats all type variables as freshly bound and links them to the context through equalities.
The paper also discusses the challenges of treating universals and existentials uniformly in pattern matching and presents a solution that allows variables to be brought into scope as renamings of existing in-scope internal variables.
Closed pattern signatures are introduced, allowing users to annotate patterns with type signatures. The paper provides a new typing rule for closed pattern signatures and explains how the subtyping relationship is checked with respect to the annotated type.
The paper explores the interpretation of assumed equalities in the context as let-bindings and extends the existing approach to include such forms. It argues that this extension is independently useful and does not negatively affect type inference.
Finally, support for open pattern signatures is introduced, which brings type variables into scope. The typing rule for annotated patterns is modified to allow the binding of type variables and the tracking of internal variables.
In conclusion, the paper extends the existing type system with lexically scoped type variables to support GADTs and pattern synonyms. It provides a detailed explanation of the modifications made to the type system and illustrates their approach with examples. The authors argue that their design is flexible and extensible while addressing potential issues and limitations.
903 word summary
The paper discusses the need for language support for lexically scoped type variables in Haskell. It highlights the shortcomings of the existing ScopedTypeVariables extension, which allows type variables to be bound in type signatures and patterns but has never been formally specified. The paper proposes visible type application in patterns as a natural extension to GHC's existing visible type applications from terms to patterns. This feature allows users to explicitly specify the type arguments of data constructors in patterns, providing a more concise and elegant syntax compared to pattern signatures.
The paper also addresses the issue of binding existentially quantified type variables in patterns. It introduces the concept of visible type application in patterns for both universal and existential variables. This allows users to bring type variables into scope and disambiguate data constructors that involve existential types. The paper provides examples to illustrate how visible type application in patterns can be used effectively.
Furthermore, the paper discusses the limitations and shortcomings of pattern signatures, which are currently used to bind type variables in patterns. It highlights the clumsiness and difficulty of using pattern signatures, particularly when type variables are deeply nested within complex types. The paper argues that visible type application in patterns is a more flexible and intuitive solution to this problem.
The formal specification of the proposed language extensions is provided in the paper. The specification includes the grammar and typing rules for the language without scoped type variables or type equalities, as well as the updates to the grammar and typing rules to accommodate these features. The paper concludes by highlighting the benefits of visible type application in patterns and the need for further exploration and implementation of these language extensions.
In summary, the paper presents a formal specification of lexically scoped type variables in Haskell. It introduces visible type application in patterns as a more concise and elegant alternative to pattern signatures for binding type variables. The paper also addresses the challenges of binding existentially quantified type variables in patterns and provides a solution through visible type application. The formal specification of the language extensions is provided, along with examples and discussions of their benefits and limitations.
The paper discusses the addition of support for Generalized Algebraic Data Types (GADTs) and pattern synonyms in a type system with lexically scoped type variables. The authors extend the existing type system to handle GADTs by introducing existential type variables and equality constraints. They also introduce pattern synonyms, which allow users to define new patterns and bind type variables within them.
In the extended type system, polytypes can now include constraints, which can be empty, an equality between monotypes, or a conjunction of constraints. The environment is extended to track the scope of type variables and the constraints that are in scope. Constraints are proved by an entailment relation, which is left abstract in the paper.
Data constructor types are modified to support GADTs. The return type of a constructor is no longer limited to a quantified type variable, but can be any monotype. Constructors can also include constraints. When a data constructor is used in an expression, the type equalities must be satisfied in the current environment.
Pattern matching with GADTs requires bringing type variables into scope and adding the learned type equalities to the environment. The paper updates the typing rules for pattern matching to prevent skolem escape and track internal variables brought into scope.
The authors note that their type system is comparable in expressiveness to existing specifications. They highlight the importance of handling nested patterns correctly in the presence of GADTs, as the order of pattern matching matters. They provide an example to illustrate this point.
One technical contribution of the paper is a simplified and more uniform rule for pattern matching with GADTs. The authors argue that their approach does not differentiate between universal and existential type variables, instead treating all type variables as freshly bound and linking them to the context through equalities.
The paper also discusses the challenges of treating universals and existentials uniformly in pattern matching. It describes how assumed local constraints can interfere with type inference and presents a solution that allows variables to be brought into scope as renamings of existing in-scope internal variables.
The authors then introduce closed pattern signatures, which allow users to annotate patterns with type signatures. They provide a new typing rule for closed pattern signatures and explain how the subtyping relationship is checked with respect to the annotated type.
The paper explores the interpretation of assumed equalities in the context as let-bindings and extends the existing approach to include such forms. The authors argue that this extension is independently useful and does not negatively affect type inference.
Finally, the paper introduces support for open pattern signatures, which bring type variables into scope. The typing rule for annotated patterns is modified to allow the binding of type variables and the tracking of internal variables. The authors explain how the existence of internal variables in the rule ensures that the bound variables are merely renamings of existing in-scope internal variables.
In conclusion, the paper extends the existing type system with lexically scoped type variables to support GADTs and pattern synonyms. The authors provide a detailed explanation of the modifications made to the type system and illustrate their approach with examples. They argue that their design is flexible and extensible, and they address potential issues and limitations of their approach.