Skip to content
0:00 / 0:00

#typeclasses#haskell#purescript

Compose :: Melbourne 2017 - George Wilson - Type Class: The Ultimate Ad Hoc

Compose Conference

2.9K subscribers • 28 videos on Hallway

YouTube
  • Recommended by 1 person: 1 in engineering communities.
  • Presented by George Wilson

Intermediate. Assumes working knowledge.

5.5K views9 years ago1 recommendation

Programming languagesSoftware designFunctional programmingLanguage design and type systems

George Wilson explores type classes as a principled solution to ad hoc polymorphism, comparing them to Java interfaces and Scala implicits.

composeconference.org/2017-melbourne/speaker-george-wilson#h… Since their inception in Haskell, type classes have become a popular feature of modern functional programming. Indeed, key topics in FP often take the form of type classes, such as Monoid and Functor. Many languages developed since Haskell have included type classes in their design, such as Idris and Purescript; or offered facilities capable of simulating type classes, such as Scala's implicits or OCaml's modules. In this talk we go beyond the basics with type classes. First we'll differentiate between parametric and ad hoc polymorphism, and we'll see why type classes are a compelling solution to the latter. By comparing them to other solutions - Java interfaces and Scala implicits - we'll see the advantages of type classes. In particular, we will focus on why type classes are principled. This section will include examples in Java, Scala, and Haskell. In order to be principled, there are conditions on the creation of instances: there can be a maximum of one instance for a given type for a given type class, and it must be in one of two allowed places. We will justify this rigidity by discussing instance coherence and its benefits, with examples of incoherence silently causing bugs. We will learn what orphan instances are and why they can be problematic for coherence. Finally, practical guidelines will be given for programmers aiming to simulate type classes in other languages, as is popular in the Scala community. These guidelines, when followed with discipline, will allow one to recover many of the benefits of type classes. Examples in this section will be in Scala. Goal Attendees will leave knowing the difference between parametric and ad hoc polymorphism, and they will understand why type classes are a principled approach to the latter. Attendees wishing to simulate type classes in a capable language, such as Scala, will leave the talk with practical guidelines helping them to do so. About George Wilson George Wilson is an enthusiastic functional programmer at the Queensland Functional Programming Lab, under Data61/CSIRO, located in Brisbane, Australia. George co-organises the Brisbane Functional Programming Group and enjoys teaching and learning functional programming and related areas of mathematics.

Why it's here

1 person recommends this

u/sordinain r/haskell • Recommends

Compose :: Melbourne 2017 - George Wilson - Type Class: The Ultimate Ad Hoc

u/calebhJuniperin r/ProgrammingLanguages • Mentions

On “Exploring multiple type class instances per type via phantom type variables”

In Scala the modular implicit system can lead to undesirable and unexpected results. This video covers the issue nicely: link to this video Perhaps the situation is different in OCaml. Personally I find type classes to be easier to use in most cases. Unfortunately the tagging solution I proposed also has problems, which I covered in the last comment of the Gist. I have seen the 1ML language before, but I've never actually used it myself.