Scala for generic programmers: Comparing haskell and scala support for generic programming

  • Authors:
  • Bruno c. d. s. Oliveira;Jeremy Gibbons

  • Affiliations:
  • Rosaec center, seoul national university, 599 gwanak-ro, gwanak-gu, seoul 151-744, south korea (e-mail: bruno@ropas.snu.ac.kr);Oxford university computing laboratory, wolfson building, parks road, oxford ox1 3qd, uk (e-mail: jg@comlab.ox.ac.uk)

  • Venue:
  • Journal of Functional Programming
  • Year:
  • 2010

Quantified Score

Hi-index 0.00

Visualization

Abstract

Datatype-generic programming (DGP) involves parametrization of programs by the shape of data, in the form of type constructors such as ‘list of’. Most approaches to DGP are developed in pure functional programming languages such as Haskell. We argue that the functional object-oriented language Scala is in many ways a better choice. Not only does Scala provide equivalents of all the necessary functional programming features (such as parametric polymorphism, higher-order functions, higher-kinded type operations, and type-and constructor-classes), but it also provides the most useful features of object-oriented languages (such as subtyping, overriding, traditional single inheritance, and multiple inheritance in the form of traits). Common Haskell techniques for DGP can be conveniently replicated in Scala, whereas the extra expressivity provides some important additional benefits in terms of extensibility and reuse. We illustrate this by comparing two simple approaches in Haskell, pointing out their limitations and showing how equivalent approaches in Scala address some of these limitations. Finally, we present three case studies on how to implement in Scala real DGP approaches from the literature: Hinze's ‘Generics for the Masses’, Lämmel and Peyton Jones's ‘Scrap your Boilerplate with Class’, and Gibbons's ‘Origami Programming’.