Abstract

Abstract This paper discusses ambiguity in the context of languages that support context-dependent overloading, such as Haskell. A type system for a Haskell-like programming language that supports context-dependent overloading and follow the Hindley-Milner approach of providing context-free type instantiation, allows distinct derivations of the same type for ambiguous expressions. Such expressions are usually rejected by the type inference algorithm, which is thus not complete with respect to the type system. Also, Haskell’s open world approach considers a definition of ambiguity that does not conform to the existence of two or more distinct type system derivations for the same type. The article presents an alternative approach, where the standard definition of ambiguity is followed. A type system is presented that allows only context-dependent type instantiation, enabling only one type to be derivable for each expression in a given typing context: the type of an expression can be instantiated only if required by the program context where the expression occurs. We define a notion of greatest instance type for each occurrence of an expression, which is used in the definition of a standard dictionary-passing semantics for core Haskell based on type system derivations, for which coherence is trivial. Type soundness is obtained as a result of disallowing all ambiguous expressions and all expressions involving unsatisfiability in the use of overloaded names. Following the standard definition of ambiguity, satisfiability is tested—i.e., “the world is closed” —if only if overloading is (or should have been) resolved, that is, if and only if there exist unreachable variables in the constraints on types of expressions. Nowadays, satisfiability is tested in Haskell, in the presence of multi-parameter type classes, only upon the presence of functional dependencies or an alternative mechanism that specifies conditions for closing the world, and that may happen when there exist or not unreachable type variables in constraints. The satisfiability trigger condition is then given automatically, by the existence of unreachable variables in constraints, and does not need to be specified by programmers, using an extra mechanism.

Highlights

  • Parametric polymorphism allows instantiation of quantified variables α, in quantified types ∀α. σ, to all types [α := τ ]σ, that is, every type generated from σ by replacing free occurrences of type variable α in σ by an arbitrary type τ

  • Constrained polymorphism is supported in programming languages like Haskell by context-dependent overloading, which is a form of overloading in which the decision of which definition of an overloaded name is used depends on the context where this name is used

  • This paper presents an alternative approach where there is no conflict with the standard semantic definition of ambiguity, built upon the distinction between ambiguity and resolved overloading

Read more

Summary

Introduction

Parametric polymorphism allows instantiation of quantified variables α, in quantified types ∀α. σ, to all types [α := τ ]σ, that is, every type generated from σ by replacing free occurrences of type variable α in σ by an arbitrary type τ (the notion of free and bound variables is well known; see, e.g., [1,2]). A type system for a Haskell-like programming language, that supports context-dependent overloading and follow the Hindley-Milner approach of providing context-free type instantiation, allows distinct derivations of the same type to be derivable for some expressions, which are ambiguous. Such expressions are usually rejected by the type inference algorithm, which becomes not complete with respect to the type system. This article addresses this issue by considering an alternative approach that disallows contextindependent type instantiation for type systems that support context-dependent overloading.

Ambiguity and overloading resolution
Core language
Entailment
Satisfiability
Improvement
Context reduction
Semantics
Conclusion
Full Text
Published version (Free)

Talk to us

Join us for a 30 min session where you can share your feedback and ask us any queries you have

Schedule a call