skip to main content
10.1145/3136000.3136006acmconferencesArticle/Chapter ViewAbstractPublication PagessplashConference Proceedingsconference-collections
research-article

The limitations of type classes as subtyped implicits (short paper)

Published: 22 October 2017 Publication History

Abstract

Type classes enable a powerful form of ad-hoc polymorphism which provide solutions to many programming design problems. Inspired by this, Scala programmers have striven to emulate them in the design of libraries like Scalaz and Cats.
The natural encoding of type classes combines subtyping and implicits, both central features of Scala. However, this encoding has limitations. If the type class hierarchy branches, seemingly valid programs can hit implicit resolution failures. These failures must then be solved by explicitly passing the implicit arguments which is cumbersome and negates the advantages of type classes.
In this paper we describe instances of this problem and show that they are not merely theoretical but often arise in practice. We also discuss and compare the space of solutions to this problem in Scala today and in the future.

References

[1]
Aloïs Cochard. 2017. aloiscochard/scato: An exploration of purely functional library design in Scala. (2017). https://github.com/aloiscochard/scato
[2]
Derek Dreyer, Robert Harper, and Manuel M.T. Chakravarty. 2007. Modular Type Classes. In ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages . Nice, France. https://people.mpi-sws.org/~dreyer/ papers/mtc/main-short.pdf
[3]
Haskell.org. 2017a. Haskell Language. (2017). https://www.haskell.org/
[4]
Haskell.org. 2017b. Haskell/Alternative and MonadPlus. (2017). https://wiki.haskell.org/Typeclassopedia#Failure_and_choice: _Alternative.2C_MonadPlus.2C_ArrowPlus
[5]
Mark Jones. 1995. Functional Programming with Overloading and HigherOrder Polymorphism. Springer-Verlag Lecture Notes in Computer Science 925 (1995).
[6]
Edward Kmett. 2017. mtl: Monad classes, using functional dependencies. (2017). https://hackage.haskell.org/package/mtl
[7]
LAMP@EPFL. 2017a. Dotty. (2017). http://dotty.epfl.ch
[8]
LAMP@EPFL. 2017b. lampepfl/dotty #2047: Allow Typeclasses to Declare Themselves Coherent. (2017). https://github.com/lampepfl/dotty/issues/ 2047
[9]
OCaml.org. 2017. OCaml - OCaml. (2017). http://ocaml.org/
[10]
Simon Peyton Jones, Mark Jones, and Erik Meijer. 1997. Type classes: an exploration of the design space. In Haskell workshop. Amsterdam. https://www.microsoft.com/en-us/research/publication/ type-classes-an-exploration-of-the-design-space/
[11]
Rust-lang.org. 2017. The Rust Programming Language. (2017). https: //www.rust-lang.org/en-US/
[12]
Scalaz. 2017a. scalaz/scalaz: An extension to the core Scala library for functional programming. (2017). https://github.com/scalaz/scalaz
[13]
Scalaz. 2017b. scalaz/scalaz series/8.0.x: An extension to the core Scala library for functional programming. (2017). https://github.com/scalaz/ scalaz/tree/series/8.0.x
[14]
Typelevel. 2017a. typelevel/cats: Lightweight, modular, and extensible library for functional programming. (2017). https://github.com/typelevel/ cats
[15]
Typelevel. 2017b. typelevel/cats-mtl: cats transformer type classes. (2017). https://github.com/typelevel/cats-mtl
[16]
Philip Wadler and Stephen Blott. 1989. How to make ad-hoc polymorphism less ad hoc. In ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages . Austin, Texas. http://homepages.inf.ed.ac.uk/ wadler/topics/type-classes.html#class
[17]
Leo White, Frédéric Bour, and Jeremy Yallop. 2014. Modular implicits. In ML Family/OCaml Users and Developers . Gothenburg, Sweden. http: //www.lpw25.net/ml2014.pdf

Cited By

View all
  • (2019)Apla Generic Constraint Matching Detection and Verification2019 24th International Conference on Engineering of Complex Computer Systems (ICECCS)10.1109/ICECCS.2019.00030(210-219)Online publication date: Nov-2019

Index Terms

  1. The limitations of type classes as subtyped implicits (short paper)

    Recommendations

    Comments

    Information & Contributors

    Information

    Published In

    cover image ACM Conferences
    SCALA 2017: Proceedings of the 8th ACM SIGPLAN International Symposium on Scala
    October 2017
    77 pages
    ISBN:9781450355292
    DOI:10.1145/3136000
    Permission to make digital or hard copies of all or part of this work for personal or classroom use is granted without fee provided that copies are not made or distributed for profit or commercial advantage and that copies bear this notice and the full citation on the first page. Copyrights for components of this work owned by others than the author(s) must be honored. Abstracting with credit is permitted. To copy otherwise, or republish, to post on servers or to redistribute to lists, requires prior specific permission and/or a fee. Request permissions from [email protected].

    Sponsors

    In-Cooperation

    Publisher

    Association for Computing Machinery

    New York, NY, United States

    Publication History

    Published: 22 October 2017

    Permissions

    Request permissions for this article.

    Check for updates

    Author Tags

    1. Scala
    2. implicits
    3. subtyping
    4. type classes

    Qualifiers

    • Research-article

    Conference

    SPLASH '17
    Sponsor:

    Upcoming Conference

    Contributors

    Other Metrics

    Bibliometrics & Citations

    Bibliometrics

    Article Metrics

    • Downloads (Last 12 months)8
    • Downloads (Last 6 weeks)0
    Reflects downloads up to 14 Feb 2025

    Other Metrics

    Citations

    Cited By

    View all
    • (2019)Apla Generic Constraint Matching Detection and Verification2019 24th International Conference on Engineering of Complex Computer Systems (ICECCS)10.1109/ICECCS.2019.00030(210-219)Online publication date: Nov-2019

    View Options

    Login options

    View options

    PDF

    View or Download as a PDF file.

    PDF

    eReader

    View online with eReader.

    eReader

    Figures

    Tables

    Media

    Share

    Share

    Share this Publication link

    Share on social media