Resolving Ambiguous Types in Haskell by Checking Uniqueness of Type Variable Assignments under Type Class Constraints

The type class mechanism, which introduces ad-hoc polymorphism into programming languages, is commonly used to realize overloading. However, this forces programmers to write many type annotations in their programs to resolve ambiguous types. Haskell's type defaulting rules reduce requirements f...

Ausführliche Beschreibung

Gespeichert in:
Bibliographische Detailangaben
Veröffentlicht in:Journal of Information Processing 2019, Vol.27, pp.87-94
Hauptverfasser: Kono, Yuya, Kawabata, Hideyuki, Hironaka, Tetsuo
Format: Artikel
Sprache:eng
Schlagworte:
Online-Zugang:Volltext
Tags: Tag hinzufügen
Keine Tags, Fügen Sie den ersten Tag hinzu!
Beschreibung
Zusammenfassung:The type class mechanism, which introduces ad-hoc polymorphism into programming languages, is commonly used to realize overloading. However, this forces programmers to write many type annotations in their programs to resolve ambiguous types. Haskell's type defaulting rules reduce requirements for annotation. Furthermore, the widely used Glasgow Haskell Compiler (GHC) has an ExtendedDefaultRules (EDR) extension that facilitates interactive sessions so that the programmer avoids problems that frequently occur when using values like [] and Nothing. However, the GHC EDR extension sometimes replaces type variables with inappropriate types, so that, for example, the term show.read that is determined to have type String -> String under the GHC EDR extension does not exhibit any meaningful behavior because the function read in the term is considered to have type String -> (). We present a flexible way of resolving ambiguous types that alleviates this problem. Our proposed method does not depend on default types defined elsewhere but rather assigns a type to a type variable only when the candidate is unique. It works with any type and type class constraints. The type to be assigned is determined by scanning a list of existing type class instances that meet the type class constraints. This decision is lightweight as it is based on operations over sets without using algorithms that require backtracking. Our method is preferable to using the GHC EDR extension since it avoids the use of unnatural type variable assignments. In this paper, we describe the details of our method. We also discuss our prototype implementation that is based on the GHC plugins, and the feasibility of modifying GHC to incorporate our method.
ISSN:1882-6652
1882-6652
DOI:10.2197/ipsjjip.27.87